【发布时间】:2018-03-09 18:38:06
【问题描述】:
我有两个单独的命令可以在两个不同的终端中运行。
场景 1: 当我在没有 bash 脚本的情况下执行此操作时
在 1 号航站楼: ./executable1 -param conFile > output1.txt
在 2 号航站楼: ./executable2 -param conFile > output2.txt
它工作并将输出写入两个单独的文件中。
场景 2: 这是我使用 bash 脚本并遇到问题的地方。 我有以下 bash 脚本:
#!/bin/bash
gnome-terminal -e "./executable1 -param conFile > output1.txt"
sleep 5
echo "Fired first Command"
gnome-terminal -e "./executable2 -param conFile > output2.txt"
echo "Fired Second command"
它既不创建 output1.txt 也不创建 output2.txt。 我如何做到这一点?
我又尝试了一件事:
./mybashscript.sh >output.txt
但它会生成一个输出文件,其内容仅为:
Fired first Command
Fired Second command
我期待 command1 和 command2 的输出,它只给了我 bash 文件的 echo 部分。
但我需要两个不同文件中两个命令的输出。
注意:这两个命令中,第一个是接收者,第二个是发送者。所以,我必须一个接一个地打开它们。
【问题讨论】:
-
你为什么使用
gnome-terminal?如果你只是背景bashes,你有更好的成功吗?bash -e "./executable1 -param conFile > output1.txt" & -
我同意@StephenNewell,除了我会更进一步,为什么要分叉另一个shell?为什么不在当前 shell 中运行两个后台进程?
./executable1 -param conFile > output1.txt & sleep 5; echo "Fired first Command"; ./executable2 -param conFile > output2.txt & echo "Fired Second command"
标签: bash gnome-terminal