Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Win32::Process::Create fails when i use ">" to redirect the screen output to a file

by Anonymous Monk
on Aug 28, 2012 at 01:10 UTC ( #990106=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

i am trying to use win32::process::Create() on my windows server 2008 and i want to redirect my screen output to log.txt so i am using code shown below but its giving me errors

Error looks like this,

ERROR: INIT: '>' is an unrecognized command line parameter

ERROR: INIT: 'log.txt' is an unrecognized command line parameter

ERROR: INIT: '2>&1' is an unrecognized command line parameter

use strict; use warnings; use Win32::Process qw(); Win32::Process::Create($ProcessObj, "C:\\winnt\\system32\\notepad.exe", "notepad temp.txt > log.txt 2>&1", 0, NORMAL_PRIORITY_CLASS, ".")|| die ErrorReport();

Comment on Win32::Process::Create fails when i use ">" to redirect the screen output to a file
Download Code
Re: Win32::Process::Create fails when i use ">" to redirect the screen output to a file
by prayaspatel (Initiate) on Aug 28, 2012 at 01:14 UTC

    Any help would be appreciated for above question....i can provide more information if you want

      I am open to correction, but I believe that > would not be a part of the command line passed to notepad, but rather would be passed to your shell (cmd.exe, cygwin's sh, whatever).

      Also I don't think that notepad.exe actually outputs anything to the console under usual circumstances, being a completely GUI application.

      I do not believe cmd.exe supports 2>&1 style redirects (apparently it does, see here, thanks for the headsup), so you would have to be using cygwin's sh or perhaps SUA perl. In that case, why aren't you just using system, qx or open?
        Hi,
        Just a minor correction - cmd.exe *does* support 2>&1 (and the like) redirection.

        Cheers,
        Rob
        i am using tool.exe but i just mentioned notepad.exe to give as an example. sorry about that. when i only put tool.exe without putting "> log.txt 2>&1" in Win32::Process::Create() it works fine.

        Also, i can run "tool.exe > log.txt 2>&1" directly from commandline but when i try to use it using Win32::Process::Create() its giving those errors that i mentioned in my initial question.

Re: Win32::Process::Create fails when i use ">" to redirect the screen output to a file
by prayaspatel (Initiate) on Aug 28, 2012 at 16:16 UTC

    i am using tool.exe but i just mentioned notepad.exe to give as an example. sorry about that. when i only put tool.exe without putting "> log.txt 2>&1" in Win32::Process::Create() it works fine. Also, i can run "tool.exe > log.txt 2>&1" directly from commandline but when i try to use it using Win32::Process::Create() its giving those errors that i mentioned in my initial question.

      tool.exe is not a shell, it isn't processing "> log.txt 2>&1" so stop giving it that, it doesn't know what to do with that information

      The program you want to call is cmd.exe, read more at  help cmd and Win32::Process redirect CMD output to text file

        its working when i use "cmd.exe" and provide " too.exe -h" as commandline but the problem is when i want to kill it its killing cmd.exe....but actully i wanted to kill tool.exe

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://990106]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (14)
As of 2014-07-10 20:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (215 votes), past polls