0

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,

4
  • 1
    What happens when you debug it? What does "not working" mean in this context? Commented Nov 11, 2015 at 14:55
  • 1
    Read the process's output. Commented Nov 11, 2015 at 14:56
  • Ernst, by not working, is it is not executing the program and converting the pcap file to plain text. Commented Nov 11, 2015 at 16:16
  • CodeCaster, there are not errors in the Output window. Last item it shows is that the thread 0x32a0 has exited with code 0 (0x0). Commented Nov 11, 2015 at 16:18

2 Answers 2

4

> 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.

Sign up to request clarification or add additional context in comments.

6 Comments

Luaan, this is the example that I used, changing the program names for what I needed; Example: Launch Legacy Program or .exe file mindstick.com/Articles/4d9e98c9-8d11-41d6-ae36-8856c2b62be4/…
@BrianCook That article never mentions using the redirection operator. It doesn't even redirect the outputs. How is it relevant?
I added the redirect on the first run of the program, and it exported the file to plain text. I deleted the plain text file, ran the program again without modifications and it did not produce the file. that is what is confusing here. I did not know that it does not read after the redirect, and without that the cmd line program will not convert to the plain text format.
@BrianCook RedirectStandardOutput means "redirect the standard output to the StandardOutput stream property", not "redirect to file". Most likely, the file already existed from some previous attempt. When you added RedirectStandardOutput without reading the stream, the application has no choice but to hang. Even if you didn't, it wouldn't produce a file. Just read the stream and write it to a file yourself, it's not that hard :)
Luaan, the redirect > symbol in the command line has to be there. The tshark.exe expects that so it knows what the filename/file type is for the conversion from Binary to Plain Text. The RedirectStandardOutput in this case may not be needed, and I will remove it for the time being to see if that allows it to run correctly again.
|
0

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

1 Comment

Thanks, I will give this example a try. I had not seen this one.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.