Call another program using system

S

sonet

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?
 
A

Andy

Your command line program is a separete entity from your PERL program.
Unless your command line program accepts command line arguments when it
is called that allow it to be configured, there is nothing your PERL
program can do to suppress the window because the window is generated
by your command line interpreter and not PERL.

But, PERL does have a shell module (use Shell) that exposes some of the
type of functionality that is available in command line interpreters,
such as piping.
 
B

Brian McCauley

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::process 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::process;

Win32::process::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).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top