简体   繁体   English

在Perl中禁止Windows cmd作为系统命令

[英]Suppress windows cmd for system command in Perl

I am using a system command in Perl to execute java. 我在Perl中使用系统命令来执行Java。 I have formed an array @args that have different options to execute a jar file. 我形成了一个数组@args,它具有执行jar文件的不同选项。 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. 我也希望在Linux中也禁止这种情况。 I tried using tild but it didn't helped as below. 我尝试使用tild,但如下没有帮助。

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

Please help in figuring this out. 请帮助解决这个问题。

Use javaw instead of java . 使用javaw代替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 另请参见java.exe和javaw.exe之间的区别

I tried using Win32::SetChildShowWindow(0) and it worked perfectly. 我尝试使用Win32 :: SetChildShowWindow(0),它运行完美。 I have build Win32 module and linked Win32 library to my application. 我已经建立了Win32模块并将Win32库链接到我的应用程序。 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 您还可以在此处关注有关此问题的讨论: Perlmonks线程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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