i want execute bath file using system() , path file passed function this:
void executebatch(char* batchfile){ system(batchfile); } now issue path passed in not have escape quotes ignore spaces example user input:
"c:\\users\\500543\\documents\\batch file project\\testing.bat" how add escape quotes path passed in?
so essentually change:
"c:\\users\\500543\\documents\\batch file project\\testing.bat" to
"\"c:\\users\\500543\\documents\\batch file project\\testing.bat\""
try
system("\"c:\\users\\500543\\documents\\batch file project\\testing.bat\""); as additional question comment, have use:
char* = "\"c:\\users\\500543\\documents\\batch file project\\testing.bat\""; system(it); then.
as edited question, since you've marked question use c++, here's c++ solution how implement function correctly:
#include <sstream> int executebatch(const char* fullbatchfilename) { std::ostringstream oss; oss << '\"' << fullbatchfilename << '\"'; return system(oss.str().c_str()); } don't make xy problem now! think should have understood principle these samples: wrap batch file name within pair of double-quote characters ('\"'), shell can interpret correctly. there pure c library methods available achieve (see <cstring>) wouldn't recommend these, if can use c++ standard library.
Comments
Post a Comment