0

I am running a Perl script in which I need to start a tomcat server. After starting the server I need to execute a different linux command.

In the Perl script after starting tomcat it isn't coming out to the next line as tomcat sever is running..

system("tomcat.sh run >log.txt");
system("ls");

I tried to open the server in different terminal. But control remains there itself.

system("xterm", "-hold", "-e", " tomcat.sh run");

I tried exec in place of system but the behaviour is same.

Miller
  • 34,962
  • 4
  • 39
  • 60
smriti
  • 1,124
  • 5
  • 14
  • 35

2 Answers2

3

If you use the single string version of system then you can append an & to run your command in the background:

system("tomcat.sh run >log.txt &");

Should do the trick.

I also found a similar question here

Community
  • 1
  • 1
John C
  • 4,276
  • 2
  • 17
  • 28
2

This is because system blocks until the process finishes. I'm not sure on how to deal with such situation, you might fork it, close STDIN before you run external process etc. Instead of system, you might try IPC::System::Simple, which handles a lot of platform-specific details for you, or modules like IPC::Run or IPC::Open3.

Similar to your issue: Why does my jzip process hang when I call it with Perl's system?

Community
  • 1
  • 1
Chankey Pathak
  • 21,187
  • 12
  • 85
  • 133