问题
my batch file asking for input y/n. i run that batch file using CreateProcess() method. If i run my batch file with /y as commnad line, it not ask for input. e.g
run.bat /y
i want to run my batch file using CreateProcess() with command line /y,as above e.g, i don't know how to do this using CreateProcess() an i don't want to modify my batch file.
::CreateProcess(L"run.bat",NULL,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&startInfo,&procInfo )
, i also try this
::CreateProcess(L"run.bat",L"/y",NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&startInfo,&procInfo )
but,it not works. If anyone know how to do this,plz let me know.
::CreateProcess(L"run.bat",L"/y",NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&startInfo,&procInfo ) this works fine. it's my mistake i change in if part and my flow goes in else part. and i always change in my if part. thanks for quick reply.
回答1:
Try this
::CreateProcess(L"cmd.exe", L"/c run.bat /y", NULL, NULL, TRUE, CREATE_NEW_CONSOLE,
NULL, NULL, &startInfo, &procInfo )
As it says on MSDN
To run a batch file, you must start the command interpreter; set lpApplicationName to cmd.exe and set lpCommandLine to the following arguments: /c plus the name of the batch file.
来源:https://stackoverflow.com/questions/16996948/run-batch-file-with-y-using-createprocess-vs2010