Home Dashboard Directory Help
Search

System.Diagnostics.Process fails at redirecting output of "netsh dhcp server \\servername show scope" by Alexander Taran


Status: 

Closed
 as Not Reproducible Help for as Not Reproducible


1
0
Sign in
to vote
Type: Bug
ID: 527415
Opened: 1/27/2010 5:27:04 AM
Access Restriction: Public
0
Workaround(s)
view
0
User(s) can reproduce this bug

Description

This piece of code does not produce the expected result anymore

Process p = new Process();

p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "netsh.exe";
p.StartInfo.Arguments = string.Format( "dhcp server \\\\{0} show scope","mydhcpserver");
p.Start();

var output = p.StandardOutput.ReadToEnd().Split('\n');
p.WaitForExit();

runing "netsh" without arguments goes ok.
runing "netsh" with some other arguments goes ok.
runing same command from console produces ok results.
Details
Sign in to post a comment.
Posted by Microsoft on 5/17/2010 at 2:43 PM
Hi a-taran,

Try as a I might, I'm unable to reproduce the issue locally. I've tried running the application as a 32 bit application on a 64 bit machine but I still don't see the error, I get the normal output.

I wonder, do you see the error if you run a WOW command shell directly and then invoke netsh? C:\Windows\SysWow64\cmd.exe will give you a 32 bit shell, which is what should be run when you run cmd.exe from your 32 bit .NET Process.

If you have some other ideas on how I might be able to reproduce the bug locally, please do follow up on the connect issue and re-open it.

Sorry I could not be of any more help.

Cheers,
Matt Ellis
Software Design Engineer
Base Class Libraries

Posted by Alexander Taran on 2/1/2010 at 5:53 AM
Oh.. my first attempt to reply at your question missed your question. I'm running on 64bit win 7.
Posted by Alexander Taran on 1/28/2010 at 10:20 PM
it is definitely tied to 64 bitnes. When i changed my vs2010 project to build to "any cpu" from "x86" it happen to work as expected. Even when i made it x64 it did work.
Changing to original x86 and it fails me again.

Well, I think I've found my workaround for vs2010, although it still seems as not correct behavior.
Posted by Alexander Taran on 1/28/2010 at 10:07 PM
Netsh does work interactively when i start it via windows start. And cmd redirection to file works as well.

It also works when i start netsh from 3.5 framework.

I noticed that it won't work from under .net 4.0 when I upgraded linqpad to latest RC for .net 4.0
But since then i was able to reproduce the results under vs2010
I'm attaching a screenshot of what is going on under both versions of framework on the left side is 4.0 on the right is 3.5.
Posted by Microsoft on 1/28/2010 at 2:31 PM
Hi a-taran,

I'm trying to reproduce this locally. Can you tell me what OS you're running on? Do you see the output from netsh written to a file when using the ">" operator from the command line? Also, did you see this behavior under .NET 3.5 or just v4.0?

Cheers,
Matt
Developer - Base Class Libraries
Posted by Alexander Taran on 1/28/2010 at 10:36 AM
Yes, I did check standart error. It somehow only fails with dhcp parameter under .net 4.0 runtime. And if i spawn interactive "netsh" from under .net 4.0 dhcp command does not work as well.
Posted by David A Nelson on 1/28/2010 at 10:26 AM
Have you checked standard error?
Posted by Microsoft on 1/28/2010 at 2:58 AM
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.
File Name Submitted By Submitted On File Size  
netsh.png (restricted) 1/28/2010 -