从当前目录 C++ 打开一个 exe
我有 python 代码...但是我如何在 c++ 中做到这一点? 我对c++没有太多经验。我想要的是制作一个 exe 并将其作为自动运行放在 CD 中。它必须使用 CD 中的 xulrunner.exe 打开 CD 中的 application.ini 文件。由于每台计算机的路径都会有所不同,因此我必须执行类似的操作。
import subprocess
import os
path= os.getcwd()
final = path + '/xulrunner.exe ' + path + '/application.ini'
print final
os.system('final')
subprocess.call(['C:\\Temp\\a b c\\Notepad.exe'])
I have the python code... but how do i do it in c++?
I don't have much experience with c++. What i want is to make an exe that will be put as autorun in an cd. It has to open the application.ini file in my cd with xulrunner.exe in my cd. As the path will vary in each computer i hav to do something like this.
import subprocess
import os
path= os.getcwd()
final = path + '/xulrunner.exe ' + path + '/application.ini'
print final
os.system('final')
subprocess.call(['C:\\Temp\\a b c\\Notepad.exe'])
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不完全确定我明白你在问什么,但你可能需要“系统”功能。这将调用平台的命令处理器来执行给定的命令。
如果您的所有文件(xulrunner.exe 和 application.ini)与自动运行可执行文件位于同一目录中,则您应该能够仅依赖正确的工作目录,而无需提供完整路径。
例如:
I'm not completely sure I understand what you're asking, but you may want the 'system' function. This will invoke the platform's command processor to execute the command given.
If all of your files (xulrunner.exe and application.ini) are in the same directory as the auto-run executable, you should be able to just rely on the working directory being correct and not need to give a full path.
For example:
os.system()
是system()
,在 Win32 中getcwd()
是GetCurrentDirectory()
http://msdn.microsoft.com/en-us/library/ aa364934(VS.85).aspx
可能应该坚持使用字符串的字符缓冲区。所以,类似(未经测试,未经尝试)
os.system()
issystem()
, in Win32getcwd()
isGetCurrentDirectory()
http://msdn.microsoft.com/en-us/library/aa364934(VS.85).aspx
Probably should stick to char buffers for strings. So, something like (untested, untried)
这取决于您要实现它的平台,但在 Windows 上(假设您所在的位置是 C:\),您需要深入了解 Windows API 并使用 CreateProcess。在 Linux 上,它将是 system 或 popen(在那里不太熟悉)。
http://msdn.microsoft.com/en- us/library/ms682425%28VS.85%29.aspx
如果已知您正在运行的 EXE 位于当前工作目录(无论您的程序从何处启动),则只需使用文件名 (" xulrunner.exe") 作为名称。使用“.\xulrunner.exe”可能会更安全,但这是更偏好的。您还可以指定子目录,甚至 SetCurrentDirectory 来移动到另一个目录。
It depends on the platform you're implementing it for, but on Windows (assuming from the C:\ that's where you are), you'll need to dip into the Windows API and use CreateProcess. On Linux, it would be system or popen (not terribly familiar there).
http://msdn.microsoft.com/en-us/library/ms682425%28VS.85%29.aspx
If the EXE you're running is known to be in the current working directory (wherever your program is started from), you can simply use the filename ("xulrunner.exe") as the name. You may be safer with ".\xulrunner.exe", but that's more preference. You can also specify a subdirectory, or even SetCurrentDirectory to move to another dir.