我有两个单独的命令可以在两个不同的终端中运行。
场景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部分。
但我需要在两个不同的文件中输出两个命令。
注意:在这两个命令中,第一个是接收者,第二个命令是发送者。所以,我必须一个接一个地打开它们。
答案 0 :(得分:1)
使用
gnome-terminal -e 'bash -c "./executable1 -param conFile > output1.txt"'
因为您需要使用bash进行重定向。