Hi Robert

OK, some oddities to mention...

No CMD instance flashes up when i run my perl script from command line (so STDIN/STDOUT exist), but when i pack it inside a par file with --gui option (i.e no shell), any piping of any commands fire up a CMD instance (I am guessing no STDIN/STDOUT when packed with --gui).

The ShellExecute command works a treat, but I am unable to get the command to redirect its STDOUT to a file so I can read it afterwards.

for example, i get a return code of 42 (which is OK apparently :)

Win32::GUI::ShellExecute(0,"open","d:\\mycommand.exe",">d:\\text.txt","d:\\",SW_HIDE);

but the output file doesn't get written.

I could pack pp without the --gui option, leaving the console behind, then call hide/show on that, but it looks scrappy :(

Steve

Robert May wrote:
Steve Loughran wrote:
Is there a way to run a system command, either via a system() call, or a open(FH,"cmd |") (or any other way), and read in the output of that command, without a cmd.exe instance appearing on the screen?

From what I understand if the command is marked as a 'console' app (this is some flag in the executable header), it will always be given a console window when it starts. I can immediately think of 2 avenues that you can try:

(1) Use the Win32 API ShellExecute() function, and pass it flags that result in the console being hidden or minimised: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/functions/shellexecute.asp

Some thing like (untried):
Win32::GUI::ShellExecute(0,"","C:\\some\\path\\somecmd.exe","-options","C:\\working\\directory",SW_HIDE);

(2) Create a modified version of your command with the 'console app' bit changed - see Win32::Exe module for one way to do this (also untried)


Regards,
Rob.


Reply via email to