从当前目录 C++ 打开一个 exe

发布于 2024-09-12 04:02:56 字数 382 浏览 3 评论 0原文

我有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

寄人书 2024-09-19 04:02:56

我不完全确定我明白你在问什么,但你可能需要“系统”功能。这将调用平台的命令处理器来执行给定的命令。

如果您的所有文件(xulrunner.exe 和 application.ini)与自动运行可执行文件位于同一目录中,则您应该能够仅依赖正确的工作目录,而无需提供完整路径。

例如:

system("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:

system("xulrunner.exe application.ini");
小糖芽 2024-09-19 04:02:56

os.system()system(),在 Win32 中 getcwd()GetCurrentDirectory()

http://msdn.microsoft.com/en-us/library/ aa364934(VS.85).aspx

可能应该坚持使用字符串的字符缓冲区。所以,类似(未经测试,未经尝试)

 #include <stdio.h>

 int main(int ac, char **av) {
    char path[MAX_PATH+1];
    GetCurrentDirectory(MAX_PATH, path);
    char final[MAX_PATH * 2 + 100];
    sprintf(final, "%s /xulrunner.exe %s/application.ini", path, path);
    printf("%s", final);
    system(final);
    // not sure what the notepad call is for, probably another system call
    return 0;
 }

os.system() is system(), in Win32 getcwd() is GetCurrentDirectory()

http://msdn.microsoft.com/en-us/library/aa364934(VS.85).aspx

Probably should stick to char buffers for strings. So, something like (untested, untried)

 #include <stdio.h>

 int main(int ac, char **av) {
    char path[MAX_PATH+1];
    GetCurrentDirectory(MAX_PATH, path);
    char final[MAX_PATH * 2 + 100];
    sprintf(final, "%s /xulrunner.exe %s/application.ini", path, path);
    printf("%s", final);
    system(final);
    // not sure what the notepad call is for, probably another system call
    return 0;
 }
晨曦慕雪 2024-09-19 04:02:56

这取决于您要实现它的平台,但在 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 来移动到另一个目录。

BOOL startedProgram = CreateProcess("xulrunner.exe", "application.ini", [fill in other options as you need]);

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.

BOOL startedProgram = CreateProcess("xulrunner.exe", "application.ini", [fill in other options as you need]);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文