Question

I need to open a new terminal while the main script is still runing. When testing the commands in command line everything is OK, but when running the perl script my new terminal windows are opened and closed in less than a second.

First new terminal window to be opened:

system ('gnome-terminal', '-x', 'sh', '-c', '"sslstrip -a -k -l 8080 -w sslstrip.log"');

Second new terminal window to be opened:

system ('gnome-terminal', '-x', 'sh', '-c', '"tail -f sslstrip.log"');

As I said the windows are opened and closed very quickly. I need them to stay opened while the script still runs.

I have already tried something like:

#!/usr/bin/perl -l

use strict;
use warnings;

$| =1;

open STDOUT, '>-';
system("du /usr/lib/perl5 &");
close STDOUT;

open STDOUT, '>-';
system("xterm -e du /usr/lib/perl5 &");
close STDOUT; 

But still isn't working.

Was it helpful?

Solution

Take out the doublequotes:

system ('gnome-terminal', '-x', 'sh', '-c', 'sslstrip -a -k -l 8080 -w sslstrip.log');

The doublequotes caused the entire line to be treated as the name of the command, rather than a command followed by arguments.

However, you'll need to fork a child process and run this in there, since this runs in the foreground and system() won't return until gnome-terminal exits. You can't use & with the multi-argument system() syntax, because it doesn't run a shell, so shell metacharacters don't work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top