Sri wrote: > Hi All, > > I am writing a program in C++ which needs an input file generated from > another executable. > the syntax of exe from command line is like- > C:\ <Execuable path> < Input Argument 1> < some options > <output arguments> > > example : > C:\Program Files\Wireshark\tshark.exe -r C:\input\tcpdump.cap -R > "tcp.dstport==7275 && ulp.msSUPLPOS" -V > C:\output\dump.txt > > I have to get the C:\output\dump.txt file from above command and use it as > input for my C++ program. > I am calling the above command using Createprocess function from my > program's main() giving the "C:\Program Files\Wireshark\tshark.exe" as > application name and rest of the field as command line arguments, but Its > not working. > Can somebody guide me on this ....I have already tried other options like > system() and WinExec() but I'm getting errors as these function are not able > to parse the input arguments.
Can you show us example code? The main problem I see that you will have is the redirected output. That is generally a shell operation and doesn't necessarily work under Windows. The '>' and whatever comes after it gets parsed by the shell, which manages setting up redirection to the file. Windows doesn't really hand things off to a shell prior to executing the main NtCreateProcess() call. To redirect output, you have to set up the pipes yourself. http://msdn.microsoft.com/en-us/library/ms682499(VS.85).aspx And that enters the evil realm of NT security tokens and anonymous, duplicated pipes. This is really low-level stuff. system() will supposedly execute through the shell, but it won't under Windows. To get a program to execute through the shell (Command Prompt), use cmd /C. The easiest way to execute a program this way is to use the system() call. You should only look at CreateProcess() when the basic calls are too limited as CreateProcess() bypasses fluff but is incredibly obtuse to use (lots of weird little nuances thanks to a couple decades of backwards-compatibility). system("cmd /C \"C:\\Program Files\\Wireshark\\tshark.exe\" -r C:\\input\\tcpdump.cap -R \"tcp.dstport==7275 && ulp.msSUPLPOS\" -V > C:\\output\\dump.txt"); Try that. It should start the shell and then the shell should process the pipe properly and then execute the program, dumping the result into the file you are piping into. The only issue you might have is with the quoted string. -- Thomas Hruska CubicleSoft President Ph: 517-803-4197 *NEW* MyTaskFocus 1.1 Get on task. Stay on task. http://www.CubicleSoft.com/MyTaskFocus/
