如何运行两个C ++程序? [英] How Do I Run Two C++ Programs ?
问题描述
我有两个程序,我想以某种方式连接它们。当我在vb.net中编程时,我学会了通过按钮或类似的东西从一种形式移动到另一种形式的概念。我在考虑用c ++做同样的事情。基本上,我的程序都应该以顺序方式运行。所以,我有source.cpp和source1.cpp,我想知道是否有一种方法可以连接它们,这样当我关闭source.cpp时,source1.cpp会自动调试并运行。有没有办法做到这一点?
看起来多线程将解决您的问题。显然,它意味着运行多个代码实例。
一个简单的来自Microsoft的示例。
要在线程之间进行交互,您可以使用事件。
主要特点:
1.我的程序都应按顺序运行。
2.当我关闭source.cpp然后source1.cpp自动调试并运行。
多线程在这里没有帮助。我会忽略你的请求中的调试,并假设你真的只想要执行第二个程序。我假设这两个程序名为source.exe和source1.exe。
使用命令文件。
https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/start.mspx?mfr=true
创建命令文件。我们称之为两个.cm:
start / wait \ path\to\source.exe
start / wait \ path\to\source1.exe
优点是你不需要修改任何一个程序。这不仅限于Windows。您也可以使用bash脚本执行相同操作。
。 / path / to / source
。 /路径/到/ source1中
I have two programs and i want to connect them somehow. When i programmed in vb.net, i learnt this concept of moving from one form to the another through a button or something like that. I was thinking of doing the same stuff in c++. Basically,both my programs should run in a sequential manner. So, i have source.cpp and source1.cpp and i was wondering if there was a way to connect them such that when i close source.cpp then source1.cpp automatically debugs and runs. Is there a way to do that?
Looks like Multi-threading will solve your problem. Plainly it means running more than one instances of code.
A simple Example from Microsoft.
To interact between the threads you can use events.
Key features:
1. "both my programs should run in a sequential manner."
2. "when i close source.cpp then source1.cpp automatically debugs and runs."
Multithreading won't help here. I'll ignore the "debugs" in your request and assuming you really just want the second program to execute. I assume the two programs are named source.exe and source1.exe.
Use a command file.
https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/start.mspx?mfr=true
Create a command file. We'll call it two.cmd:
start /wait \path\to\source.exe start /wait \path\to\source1.exe
The advantage is you do not need to modify either program. This isn't limited to Windows. You can do the same from a bash script too.
. /path/to/source . /path/to/source1
这篇关于如何运行两个C ++程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!