开发者

opening an exe from current dir C++

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开发者_如何学C. 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'])


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");


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;
 }


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]);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜