Search code examples
c++linuxistreamxterm

Want to run a cpp executable in a new terminal and then send a file into the input stream


I would like to run a c++ executable in a new linux terminal, which I am doing using:

xterm -e executable options &disown

and this works. However, I also need to parse a text file through the command line. Normally, the file would be parsed by:

./executable options < inputFile.txt

and then the file is handled by the c++ code using this function:

void parse_lines(istream &in){
    verify_version_number(in);
    read_variables(in);
    ...
}

However the following line does not work:

xterm -e executable options < inputFile.txt &disown

How can I run the executable in a new terminal and then send the contents of inputFile.txt into the istream?

Thanks!


Solution

  • If you put quotes around the command, it will be sent to the shell as a single command, and the special characters < and & will be interpreted in the shell running within xterm rather than in the shell where you start xterm:

    xterm -e "executable options < inputFile.txt &disown"