【发布时间】:2015-02-19 06:39:01
【问题描述】:
我正在尝试使用 system 命令从 Perl 运行在我的 ~/.bashrc 中具有别名的命令。它只运行一次命令运行良好,但是当我运行它两次时,第二次调用作为后台作业运行,然后暂停(与按 <CTRL-Z> 相同),我必须输入 fg 才能完成命令。例如
use strict;
use warnings;
system ('bash -ic "my_cmd"');
system ('bash -ic "my_cmd"');
第二次调用永远不会完成。输出为[1]+ Stopped a.pl。
注意:
- 将
my_cmd替换为任何其他命令(例如ls)时获得相同的结果。 - 似乎与我的
~/.bashrc文件的内容无关。我试图从中删除所有内容,但问题仍然存在。
我使用的是 Ubuntu 14.04 和 Perl 版本 5.18.2。
更新
为了调试,我将~/.bashrc 减少到
echo "Entering ~/.bashrc .."
alias my_cmd="ls"
alias
和我的~/.bash_profile 到
if [ -f ~/.bashrc ]; then
echo "Entering ~/.bash_profile .."
. ~/.bashrc
fi
正在运行:
system ('bash -lc "my_cmd"');
system ('bash -lc "my_cmd"');
给予
Entering ~/.bash_profile ..
Entering ~/.bashrc ..
alias my_cmd='ls'
bash: my_cmd: command not found
Entering ~/.bash_profile ..
Entering ~/.bashrc ..
alias my_cmd='ls'
bash: my_cmd: command not found
并运行
system ('bash -ic "my_cmd"');
system ('bash -ic "my_cmd"');
给予
Entering ~/.bashrc ..
alias my_cmd='ls'
a.pl p.sh
[1]+ Stopped a.pl
【问题讨论】: