Reputation: 37
I am trying to Start a process of Wireshark, and export a .pcap file to Plain text.
From the command line, I am able to do the export, so I know that the arguments are correct and the program is in the PATH environment.
Interestingly enough, I use this piece of code one time this morning, and it worked correctly. Subsequent runs it failed to convert the file.
Here is the code I am using.
private void Button1Click(object sender, EventArgs e)
{
var stinfo = new ProcessStartInfo();
stinfo.FileName = @"c:\Program Files (x86)\Wireshark\tshark.exe";
stinfo.Arguments = "-V -r " + @"c:\Brian_00001_20151110133639.pcap" + " > " + @"c:\\Brian_00001_20151110133639.txt";
stinfo.CreateNoWindow = true;
stinfo.UseShellExecute = false;
stinfo.RedirectStandardOutput = true;
stinfo.RedirectStandardError = true;
Process myProcess = Process.Start(stinfo);
myProcess.Start();
myProcess.WaitForExit();
}
Thanks,
Upvotes: 0
Views: 1589
Reputation: 1
The process normally doesn't see whatever comes after the pipe or redirect operator (> here). That's parsed by the shell. Have you tried UseShellExecute = true? I haven't, dunno if that will do anything. But I think your parent process would need to be launched from the shell or debug options to include that output redirect. Otherwise you'll have to read the StandardOutput of the child process and dump it to a file yourself in code. https://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput%28v=vs.110%29.aspx
Upvotes: 0
Reputation: 63772
>
is not an argument, it's a shell operator. Since you're "passing" it wrong, and since you disabled UseShellExecute
, this isn't going to work.
You'll need to do the redirection manually :)
Also, once you say "sure, redirect output and error to me", you have to actually read those streams. If you don't, the application is going to hang when it runs out of space in the output buffers. This is likely why your code mysteriously stopped working - the guest application is writing more than the buffers can handle.
Upvotes: 4