【问题标题】:Open new terminal while main script still runs在主脚本仍在运行时打开新终端
【发布时间】:2013-06-25 18:47:47
【问题描述】:

我需要在主脚本仍在运行时打开一个新终端。在命令行中测试命令时一切正常,但在运行 perl 脚本时,我的新终端窗口会在不到一秒的时间内打开和关闭。

要打开的第一个新终端窗口:

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

要打开的第二个新终端窗口:

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

正如我所说,窗户打开和关闭的速度非常快。我需要它们在脚本仍在运行时保持打开状态。

我已经尝试过类似的方法:

#!/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; 

但还是不行。

【问题讨论】:

    标签: perl terminal system gnome


    【解决方案1】:

    去掉双引号:

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

    双引号导致整行被视为命令的名称,而不是命令后跟参数。

    但是,您需要派生一个子进程并在其中运行它,因为它在前台运行并且system() 直到gnome-terminal 退出才会返回。您不能将 & 与多参数 system() 语法一起使用,因为它不运行 shell,因此 shell 元字符不起作用。

    【讨论】:

    • 它适用于这些行。但是现在我面临与系统相同的问题('gnome-terminal','-x','sh','-c','arpspoof -i $interface -t $target $gateway');。除了分叉子进程之外,还有其他解决方案吗?
    猜你喜欢
    • 1970-01-01
    • 2020-05-14
    • 2017-07-09
    • 1970-01-01
    • 1970-01-01
    • 2015-07-04
    • 2021-12-09
    • 2012-11-18
    • 2016-08-06
    相关资源
    最近更新 更多