Escaping Dash Character in batch file using Visual C++ -
i working on simple program in file containing computer names read c++ file seen in following:
//previously, file containing names opened , //getline() in use read each line //note 'line' string containing current line being read string comp = lower(trim(line.erase(0, 2))); //lower converts lowercase (for later in program) , //trim trims beginning , ends of string. //i have erased first 2 characters, since contain 2 \'s ofstream bat; bat.open("names_get.bat"); if (bat.is_open()) { bat << "wmic.exe /node:"+comp+" computersystem username >compnames.txt"; bat.close(); }
this functions well. however, encountering problem when batch file executed using shellexecute. problem command prompt encountering computer names such "owner-pc" , taking - parameter, resulting in invalid global switch error. can please point me in correct direction concerning how escape dash in such event. thank you, , sorry long question!
you should surround comp
name "
like
wmic.exe /node:"prefix-suffix" computersystem username
so add \"
in code , should work
if (bat.is_open()) { bat << "wmic.exe /node:\""+comp+"\" computersystem username >compnames.txt"; bat.close(); }
Comments
Post a Comment