简体   繁体   English

在新的终端窗口中启动程序

[英]starting program in new terminal window

I have a program that needs to start another program. 我有一个程序需要启动另一个程序。 On my mac I did this using system("open path"), but on linux that doesn't work. 在我的Mac上,我使用system(“ open path”)进行了此操作,但是在linux上却不起作用。 and using system(./path) is not what I want since than it overtakes the running program. 我不想使用system(./ path),因为它超过了正在运行的程序。

So is there any way to get the same behaviour as the mac 'open path' command on linux? 那么,有没有办法获得与Linux上的Mac“开放路径”命令相同的行为?

(linux noob btw:p) (linux noob btw:p)

If you're running the application in a GUI environment, this should be possible but the approach is different. 如果您在GUI环境中运行应用程序,则应该可以,但是方法不同。 You need to start a new terminal instance explicitly. 您需要显式启动一个新的终端实例。

Determine the path to your terminal application. 确定您的终端应用程序的路径。 This depends on the linux distribution. 这取决于linux发行版。 Next, check the documentation of that particular terminal application and find out how it can be started to run an application (your application) instead of a shell. 接下来,检查该特定终端应用程序的文档,并找出如何启动它来运行应用程序(您的应用程序)而不是Shell。 This probably involves using some application-specific command line options. 这可能涉及使用一些特定于应用程序的命令行选项。 Test that in a terminal window, until you have a command line that gives you the desired result. 在终端窗口中进行测试,直到拥有可以提供所需结果的命令行为止。 Things could get a little tricky if your application needs command line arguments as well. 如果您的应用程序也需要命令行参数,事情可能会变得有些棘手。 Use the -- option where necessary. 必要时使用-选项。

Then, all you need to do is run that command line from your "parent" application. 然后,您需要做的就是从“父”应用程序运行该命令行。 I would advise however to not use system(). 但是我建议不要使用system()。 The exec... family functions (using fork and wait) provide better control. 执行...系列功能(使用fork和wait)提供更好的控制。

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

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