Search code examples
bashgnome-terminal

Firing two terminals from a single bash script and both terminals output to two separate files


I have two separate commands to runs in two different terminals.

Scenario1: When I do it without the bash script In terminal 1: ./executable1 -param conFile > output1.txt In terminal 2: ./executable2 -param conFile > output2.txt

It works and writes the output in two separate file.

Scenario 2: This is where I use a bash script and have problem. I have the following bash script:

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

It neither creates output1.txt nor output2.txt. How do I achieve this?

I tried one more thing :

./mybashscript.sh >output.txt

but it generates an output file whose contents are only:

Fired first Command
Fired Second command

I was expecting the output of the command1 and command2 and it only gives me the echo part of bash file.

But I need the output of both the commands in two different file.

Note: Among the two command first one is the receiver and second command is of sender. So,I have to open them one after another.


Solution

  • Use

    gnome-terminal -e 'bash -c "./executable1 -param conFile > output1.txt"'
    

    as you need bash for the redirection.