简体   繁体   中英

Suppress windows cmd for system command in Perl

I am using a system command in Perl to execute java. I have formed an array @args that have different options to execute a jar file. Something like below:

$args[0] = $rootpath."/jre/bin/java";
$args[1] = " -jar \"".$rootpath."/temp/abc.jar\"";
$args[2] = " INP=\"".$inputfilename."\"";
$args[3] = " OUT=\"".$outputfilename."\"";
system(@args);

This gives a popup window when executed which I want to suppress and want it to run in background. I want this to be suppressed in Linux also. I tried using tild but it didn't helped as below.

my $command = @args;
$output = `$command`;

Please help in figuring this out.

Use javaw instead of java .

This most probably boils down to changing the first line to

$args[0] = $rootpath."/jre/bin/javaw";

See also Difference between java.exe and javaw.exe

I tried using Win32::SetChildShowWindow(0) and it worked perfectly. I have build Win32 module and linked Win32 library to my application. After adding below code before calling the system command no pop-up command prompt window is displayed.

Win32::SetChildShowWindow(0) 
if defined &Win32::SetChildShowWindow;

You can also follow discussion on this here: Perlmonks thread

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM