我正在尝试在 perl 中创建简单的启动脚本,它将在系统启动时启动各种程序。如下
my @startupPrograms = qw(google-chrome thunderbird skype pidgin );
my @pagesToBeOpenedInChrome = qw(http://www.google.com/ http://stackoverflow.com/ https://mail.google.com/mail/u/0/#inbox);
sub runPrograms() {
print("Starting startup Programs... \n");
foreach (@startupPrograms) {
my $command = $_;
print "Starting Program " . $command . "\n";
if($command == "google-chrome") {
foreach (@pagesToBeOpenedInChrome) {
$command = $command . " " . $_;
}
}
`$command &`;
print "Program " . $command . " started \n";
}
}
但我得到的输出是
[aniket@localhost TestCodes]$ ./startUp.pl
***** Welcome to startup program! *****
Starting startup Programs...
Starting Program google-chrome
Program google-chrome http://www.google.com/ http://stackoverflow.com/ https://mail.google.com/mail/u/0/#inbox started
Starting Program thunderbird
Program thunderbird http://www.google.com/ http://stackoverflow.com/ https://mail.google.com/mail/u/0/#inbox started
Starting Program skype
Program skype http://www.google.com/ http://stackoverflow.com/ https://mail.google.com/mail/u/0/#inbox started
Starting Program pidgin
Program pidgin http://www.google.com/ http://stackoverflow.com/ https://mail.google.com/mail/u/0/#inbox started
为什么要执行每个命令中的 pagesToBeOpenedInChrome 数组内容?此外,如果我将 pidgin 放在其他程序之前,似乎需要永远启动 pidgin(其他程序被锁定)。任何帮助或建议表示赞赏。