Thanks for your input.

I'm attaching the sample code for createprocess at the bottom of this mail.
the error code that I'm getting from createprocess call is 2, that means
ERROR_FILE_NOT_FOUND.
I have tried many possible combination like path to the executable and
arguments in the command line field, but the same error each time.

I also tried the system(), as told by you, but here it considers the the
path "C:\\Program Files\\...." as some command or program and gives the
following error-"C:\Program' is not recognized as an internal or external
command,
operable program or batch file."

Regards,

Sri

/*************************************************sample code for
createprocess*******************************/
int main(void)
{


    STARTUPINFO si;
    PROCESS_INFORMATION pi;
    ZeroMemory( &si, sizeof(si) );
    si.cb = sizeof(si);
    ZeroMemory( &pi, sizeof(pi) );

    char cmdline[1000];
    char currdir[100];
    sprintf(cmdline,"tshark.exe -r C:\\input\\tcpdump.cap -R ulp.msSUPLPOS
-V > C:\\input\\dump.txt");
    sprintf(currdir,"C:\\Program Files\\Wireshark\\");
    // Start the child process.
    if( !CreateProcess( NULL,   // No module name (use command line)
        (LPWSTR)(cmdline),        // Command line
        NULL,           // Process handle not inheritable
        NULL,           // Thread handle not inheritable
        FALSE,          // Set handle inheritance to FALSE
        CREATE_DEFAULT_ERROR_MODE, // No creation flags
        NULL,           // Use parent's environment block
        (LPCWSTR)(currdir),           // Use parent's starting directory
        &si,            // Pointer to STARTUPINFO structure
        &pi )           // Pointer to PROCESS_INFORMATION structure
    )
    {
        printf( "CreateProcess failed (%d).\n", GetLastError() );

    }

    // Wait until child process exits.
    WaitForSingleObject( pi.hProcess, INFINITE );

    // Close process and thread handles.
    CloseHandle( pi.hProcess );
    CloseHandle( pi.hThread );


    /* rest of the program */

    return 0;


}



On Tue, Apr 28, 2009 at 7:46 PM, Thomas Hruska <[email protected]>wrote:

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



-- 
Regards
Sri


[Non-text portions of this message have been removed]

Reply via email to