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

I think Win32::Process::Create creates a new process directly from the program you send it. It does not start a shell and then have the shell start the process. Redirecting is a function of the shell. You may have to start "cmd" or "command" (depending on your shell) and have it start identify.exe in your Win32::Process::Create call.

--

flounder

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

Replies are listed 'Best First'.
Re: Re: Win32::Process redirect CMD output to text file
by sdyates (Scribe) on Jun 25, 2002 at 16:53 UTC

    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.

      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