0

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.

CVS
  • 491
  • 2
  • 4
  • 13
  • `my $foo = @bar` will give you the **number of elements** in `@bar` because that's what an array will be turned into when used in scalar context. – simbabque Jun 17 '15 at 08:21
  • See http://superuser.com/questions/233348/how-do-i-create-a-windows-batch-file-that-does-not-show-the-command-prompt-when for Windows. – simbabque Jun 17 '15 at 08:22
  • Thanks simbabque. I forgot to put double quote around @args. The link you have provided suggests using start $cmd I think for perl which I tried but it doesn't help. What could be the problem? – CVS Jun 17 '15 at 09:40
  • `java` should use the console in which your script is already executing. I have no idea why it's opening a second console for you. – ikegami Jun 17 '15 at 19:53
  • I have a C++ application that is calling perl scripts from which I am using system command. So the perl script is not running in any console. It opens new console when I am calling system command to execute java. – CVS Jun 18 '15 at 06:24

2 Answers2

1

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

CVS
  • 491
  • 2
  • 4
  • 13
1

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

Community
  • 1
  • 1
René Nyffenegger
  • 39,402
  • 33
  • 158
  • 293
  • Perfect solution what I was looking for to remove console window when calling java as system command in perl. Tons of thanks. – CVS Jun 19 '15 at 12:16