run batch file with /y using createprocess vs2010

空扰寡人 提交于 2019-12-13 04:24:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!