简体   繁体   English

如何使用fork()和execlp()在不同的终端上运行命令

[英]how to run a command on different terminal using fork() and execlp()

I had written a program using NCURSES in which i am displaying a menu on one terminal and want to use fork() and execlp() in the same program but whatever command i am running using fork() and execlp() had to be executed on a different terminal or in the back ground.How that can be done.I am simply using 我已经使用NCURSES编写了一个程序,其中我在一个终端上显示菜单,想在同一程序中使用fork()和execlp(),但是我必须使用fork()和execlp()运行的任何命令都必须执行在不同的终端或背景上。如何做到这一点,我只是在使用

if(fork())
wait(0);
else
execlp("ls","ls",(char *)NULL);

within a conditional statement which is displaying a message on the main terminal and will be executing the command inside execlp in the background 在条件语句中,该条件语句在主终端上显示一条消息,并将在后台执行execlp中的命令

You probably need to start a new terminal, and hand it the command to run. 您可能需要启动一个新终端,然后将其交给命令来运行。

If you look at the command line parameters of eg gnome-terminal you can figure out how to format the command line. 如果查看例如gnome-terminal的命令行参数,则可以了解如何格式化命令行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM