in reply to Re: Win32::Process redirect CMD output to text file
in thread Win32::Process redirect CMD output to text file

Eitherway, I should be able to redirect the contents of the command from the screen to a file on disk. If I can do this using system, I am sure I can do it with Win32::Process, just cannot figure out how to do it. I cannot believe that Win32::Process would be lacking in that area. I am more convinces in my own ignorance that Win32's ignorance.

  • Comment on Re: Re: Win32::Process redirect CMD output to text file

Replies are listed 'Best First'.
Re^3: Win32::Process redirect CMD output to text file
by flounder99 (Friar) on Jun 25, 2002 at 17:15 UTC
    Here, look at this
    use Win32::Process; Win32::Process::Create($ProcessObj, 'c:\winnt\system32\cmd.exe', "/c echo foo>foo.txt", 0, NORMAL_PRIORITY_CLASS,".")||warn "could not create process";
    instead of echo foo put in the program you want to run. Win32::Process is doing what you ask of it - it is creating a process running "identify.exe". "indentify.exe" does not know how to redirect. You have to run "cmd.exe" and have it start "identify.exe" and redirect the output to a file. system transparently starts a shell (cmd.exe) and hands it the parameters, the first of which is the program it should run. Most people from a windows background don't understand that a command prompt is actually a program called "cmd.exe" (or "command.com" on dos/win9x)

    Update:
    Note: the name of your shell is probably available in $ENV{COMSPEC}

    --

    flounder

      It is always sonething simple!!! Thanks so much... Thinking too much in one way. Now I just have to solve my other bugs :)

      Starting Process and redirecting output works well, but another problem arises: I cannot kill the process started by cmd i.e. identify.exe. Only the cmd.exe is killed, identify.exe continues. Thanks for any help

        Starting Process and redirecting output works well, but another problem arises: I cannot kill the process started by cmd i.e. identify.exe. Only the cmd.exe is killed, identify.exe continues

        i also have the same problem....did you find the solution? i want to kill identify.exe ...but its satarting and killing cmd.exe