-1

Assume that the batch file is executed by the process created by the createProcess() function. The path of the file is given as the first argument to the createProcess() function. How can i pass arguments to this batch file?

Does using lpCommandLine parameter to pass arguments result in any problem if the parameters are strings which contain spaces within them? For example, "abc=20 xyz=10" and "def=5 ggg=15" are two arguments to be passed. My question is does having spaces (" ") within the string will be a problem and how do i pass them as two separate arguments?

RRR
  • 81
  • 1
  • 10
  • This doesn't sound like a batch related question. Include this line to your batch to show args `Echo Args:%* & Pause` to see if there are any args. Otherwise it's C/c++/whatever related. ' –  Nov 16 '16 at 13:05
  • The command line is passed via the lpCommandLine parameter. Just concatenate the arguments separated by spaces into the string you pass for that parameter. It's unclear if that's the issue or if you don't know how to handle parameters in the batch file itself which is a very different question. You should clarify. This may help: http://stackoverflow.com/questions/25919451/use-createprocess-to-run-a-batch-file – Retired Ninja Nov 16 '16 at 22:44
  • But in lpCommandLine parameter can i pass a set of strings as parameters. For example, "abc=20 xyz=10" and "def=5 ggg=15" are two arguments to be passed. My question is does having spaces (" ") within the strings will be a problem and how do i pass them as two separate arguments? @RetiredNinja – RRR Nov 17 '16 at 07:51
  • If you have spaces in your arguments you need to enclose them in quotes. It's not a bad idea to just do that for all arguments just in case. – Retired Ninja Nov 17 '16 at 13:42

1 Answers1

0

Could you use _spawnlp instead:

if (_spawnlp(_P_WAIT,"C:\\myfile.bat","myfile.bat","arg1-as-text","arg2-as-text",NULL) != 0)
    {
    reportError("Error running myfile.bat");
    }
Marcus
  • 261
  • 2
  • 5