使用createprocess vs2010使用/ y运行批处理文件(run batch file with /y using createprocess vs2010)

编程入门 行业动态 更新时间:2024-10-28 20:24:18
使用createprocess vs2010使用/ y运行批处理文件(run batch file with /y using createprocess vs2010)

我的批处理文件要求输入y / n。 我使用CreateProcess()方法运行该批处理文件。 如果我使用/ y作为commnad行运行我的批处理文件,它不会要求输入。 例如

run.bat /y

我想用命令行/ y使用CreateProcess()运行我的批处理文件,如上所述,例如,我不知道如何使用CreateProcess()来执行此操作,我不想修改我的批处理文件。

::CreateProcess(L"run.bat",NULL,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&startInfo,&procInfo ) ,我也试试这个

::CreateProcess(L"run.bat",L"/y",NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&startInfo,&procInfo )

但是,它不起作用。 如果有人知道怎么做,请告诉我。

:: CreateProcess(L“run.bat”,L“/ y”,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&startInfo,&procInfo)这很好用。 这是我的错误,我改变了如果部分和我的流程进入其他部分。 我总是改变我的if部分。 谢谢你的快速回复。

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.

最满意答案

尝试这个

::CreateProcess(L"cmd.exe", L"/c run.bat /y", NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &startInfo, &procInfo )

正如它在MSDN上所说的那样

要运行批处理文件,必须启动命令解释程序; 将lpApplicationName设置为cmd.exe并将lpCommandLine设置为以下参数:/ c加上批处理文件的名称。

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.

更多推荐

本文发布于:2023-07-31 06:01:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1341861.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:批处理文件   createprocess   file   batch   run

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!