I have an issue when using this command
system("konsole --new-tab --workdir<dir here> -e perlprogram.pl &");
It opens perlprogram.pl which has:
system("mpg321 song.mp3");
I want to do this because mpg321 stalls the main perl script. so i thought by opening it in another terminal window it would be ok. But when I do run the first script all it does is open a new tab and do nothing.
Am I using konsole correctly?
Likely, no. But that depends. This question can be decomposed into two issues:
konsole.1. Concurrency
There are multiple ways to do that. Starting with the
fork||exec('new-program'), tosystem 'new-program &', or evenopen.systemwill invoke the standard shell of your OS, and execute the command you provided. If you provide multiple arguments, no shell escaping is done, and the specified programexeced directly. (Theexecfunction has the same interface so far).systemreturns a number that specifies if the command ran correctly:See
perlfunc -f systemfor the full info on what this return value signifies…The
execnever returns if successfull, but morphs your process into executing the new program.forksplits your process in two, and executes the child and the process as equal copies. They only differ in the return value offork: The parent gets the PID of the child; the child gets zero. So the following executes a command asynchronously, and lets your main script execute without further delay.The above process effectively daemonizes the child (runs without a tty).
2. konsole
The command line interface of that program is awful, and it produces errors half the time when I run it with any parameters.
However, your command (plus a working directory) should actually work. The trailing ampersand isn’t neccessary, as the
konsolecommand returns immediately. Something likeworks fine for me (opens a new tab, displays “hello”, and closes when I hit enter). The final readline there keeps the tab open until I close it. You can keep the tab open until after the execution of the
-ecommand via--hold. This allows you to see any error messages that would vanish otherwise.