I need to call a command_line(CM1.EXE) from another program(APP1.pl).
in APP.pl (PERL)
#!perl.exe
system('/path/CM1.EXE 1234>file.txt');
But the CM1.exe will show the console window.
How to avoid the CM1.exe show the console window?
From the .EXE suffix I'm guessing you may be using a rather odd
operating system known as Windows (often referred to as Win32).
I believe this means that CM1.exe was compiled as a console
application. When you execute a console app exe on Windows (other than
from an existing console) Windows will open a console. (I'm guesssing
you are using wperl.exe).
You can get low-level control over how processes are launched on
Windows using the Win32:
rocess module. I suspect there's some
combination of these that will cause console apps to run without a
console (or more accurately (IIRC) with a hidden one).
use strict;
use warnings;
use Win32:
rocess;
Win32:
rocess::Create
( my ($ProcessObj),
'C:\windows\system32\cmd.exe',
'/C "\path\CM1.EXE 1234>file.txt"',
0,
NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW,
"."
) or die "$^E";
Note that this is messy because you call cmd.exe to parse the shell
redirection characters.
There ought to be a way to do the redirection in Perl without the need
for the extra level of process but when I try it seems not to play
nicely with CREATE_NO_WINDOW.
This however has (almost) nothing to do with Perl and a lot to do with
the pain of using the Windows API (whatever your chosen language).