views:

85

answers:

3

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'])
+1  A: 

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");
dauphic
+1  A: 

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]);
peachykeen
A: 

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;
 }
Lou Franco
test.cpp: In function `int main(int, char**)':test.cpp:3: error: conflicting declaration 'int ac'test.cpp:3: error: 'ac' has a previous declaration as `char**ac'test.cpp:3: error: declaration of `int ac'test.cpp:3: error: conflicts with previous declaration `char**ac'test.cpp:4: error: `MAX_PATH' was not declared in this scopetest.cpp:5: error: `path' was not declared in this scopetest.cpp:5: error: `GetCurrentDirectory' was not declared in this scopetest.cpp:7: error: `final' was not declared in this scopetest.cpp:9: error: `system' was not declared in this scope
esafwan
what could be the reason for error?
esafwan
I didn't type this into an editor or try to compile -- you're going to need to know *some* c++ to get it working. I corrected the ac/av in main. try MAXPATH or just stick a big number there. try #include <windows.h> --- I was just trying to get you started.
Lou Franco
you're going to need to google some of the functions and find #include for them
Lou Franco
just 2 error left.. but can't figure it out...test.cpp: In function `int main(int, char**)':test.cpp:7: error: `GetCurrentDirectory' was not declared in this scope
esafwan
according to the docs for GetCurrentDirectory, you need to include windows.h
Lou Franco