Thursday 15 September 2011

visual c++ - how can i execute a file kept on desktop in c++? -



visual c++ - how can i execute a file kept on desktop in c++? -

my file construction executing .exe c:\documents , settings\desktop\release\abc.exe want execute other c++ programme in vb c++ after building, generates error c:\document not external or internal command few lines of code follows:

#include<stdlib.h> #include<stdio.h> int main( void ) { int result; result=system("c:\\documents , settings\\desktop\\release\\abc.exe"); getchar(); homecoming 0; }

as suspected when writing before comment, way wrap entire string in double-quotes. 'escaping spaces' sounds non-sensical me. 25 seconds of googling , don't see (nor have heard of in on 20 years) escape-sequence space character in c.

the solution indeed include quotes in string - not wrap string in single pair of them, you've done. next trick:

#include <stdlib.h> #include <stdio.h> int main() { int result; result = system("\"c:\\documents , settings\\desktop\\release\\abc.exe\""); getchar(); homecoming 0; }

however, said - shouldn't using system phone call job. since you're on windows machine, should utilize shellexecute function instead. there many reasons this, wont go here, can them yourself. suffice it's infinitely improve way invoke program.

more on shellexecute: http://msdn.microsoft.com/en-us/library/windows/desktop/bb762153(v=vs.85).aspx

c++ visual-c++

No comments:

Post a Comment