Home Dashboard Directory Help
Search

Unable to redirect ONLY the standard input of process "cmd.exe" (or batch file) from windows form application by daat99


Status: 

Closed
 as Won't Fix Help for as Won't Fix


6
1
Sign in
to vote
Type: Bug
ID: 609801
Opened: 10/3/2010 6:15:37 AM
Access Restriction: Public
0
Workaround(s)
view
4
User(s) can reproduce this bug

Description

More info can be found on these posts:

http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/23527505-236f-4bba-99ae-f8bece281d44
http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/4ce40b19-c442-4412-94b2-1ed24bdb9386?prof=required


Basically when I attempt to redirect the standard input of a console application from windows form the console application crashes immediately.

When I use the exact same code from a console application everything works fine (this is what leads me to believe it might be a bug).

Here's the shortest code you need to reproduce the problem:


Process myProcess = new Process();
myProcess.StartInfo.FileName = @"cmd.exe";
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardInput = true;
myProcess.Start();


Please note the following:

1. When I change "cmd.exe" to "sort.exe" it works find on both console and windows form applications.

2. When compiling to windows application for 64 bit platform (or AnyCPU) the "myProcess.MainModule" throws an exception: {"Only part of a ReadProcessMemory or WriteProcessMemory request was completed"}

3. When compiling to windows application for 32 bit platform the "myProcess.MainModule" throws an exception: {"A 32 bit processes cannot access modules of a 64 bit process."}

4. When I redirect both the standard input and the standard output everything works fine.


I scanned the net and I was able to find only a few posts regarding this issue in multiple sites.

The posts I found didn't provide a solution and used the programming languages c# and vb.net.


That basically leads me to think the problem is in .NET itself.

I'm using Windows 7 x64 Ultimate and Visual Studio 2010 Ultimate with .NET 4.

I'm yet to find any workaround for redirecting only the input of a console application from a windows form application.

If you know of any workaround that allows me to do that please let me know.

Thanks in advance,

daat99
Details
Sign in to post a comment.
Posted by Adam Cabler on 3/2/2011 at 9:55 PM
I have this problem also. I'm trying to capture only stdout and stderr. The process exits immediately with:


+        base    {"Only part of a ReadProcessMemory or WriteProcessMemory request was completed"}    System.Runtime.InteropServices.ExternalException {System.ComponentModel.Win32Exception}

The workaround is to redirect all 3 streams (stdin for me) to get this to work.
Posted by Microsoft on 11/12/2010 at 4:53 PM
Thank you for reporting this issue. Customer feedback is a critical part of a successful, impactful software product. Unfortunately another part is the reality of schedules and the need to prioritize investments according to the objectives of the product. We have evaluated the issue that you have reported and at this point in the product's lifecycle, it does not meet the criteria to be addressed. This evaluation is carefully done and considers many aspects including the cost of the fix, implications of the change, and the number of reported instances of the issue.


Many customers have found it useful to discuss issues like this in the forums (http://www.microsoft.com/communities/forums/default.mspx) where Microsoft and other members of the community can recommend ways of achieving the behavior you are interested in.

Thank you,
The Windows Forms Product Team
Posted by Microsoft on 10/3/2010 at 6:21 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.