如何使用“gnome-terminal”命令启动C程序并从文件发送输入?

时间:2022-01-27 20:47:47

To clarify the question: I need to open a terminal window, execute a C program (which takes input from a file) and save its output to a file.

澄清问题:我需要打开一个终端窗口,执行一个C程序(从文件中获取输入)并将其输出保存到文件中。

I know that if I do "./program < input.txt > output.txt", I'll get what I want.

我知道如果我做“./program output.txt”,我会得到我想要的。

For some reason, if I do "gnome-terminal -e ./program < input.txt > output.txt", the program opens on a different terminal window, but doesn't take the input from input.txt nor saves the output to the output.txt file.

出于某种原因,如果我执行“gnome-terminal -e ./program output.txt”,程序将在不同的终端窗口打开,但不从input.txt获取输入也不保存输出到output.txt文件。

What am I doing wrong?

我究竟做错了什么?

2 个解决方案

#1


0  

You need bash to redirect input and output in new gnome terminal.

你需要bash来重定向新的gnome终端中的输入和输出。

    gnome-terminal -e 'bash -c "./program < input.txt > output.txt"'

#2


1  

Try gnome-terminal -e "./program < input.txt > output.txt"

试试gnome-terminal -e“./program output.txt”

#1


0  

You need bash to redirect input and output in new gnome terminal.

你需要bash来重定向新的gnome终端中的输入和输出。

    gnome-terminal -e 'bash -c "./program < input.txt > output.txt"'

#2


1  

Try gnome-terminal -e "./program < input.txt > output.txt"

试试gnome-terminal -e“./program output.txt”