从程序执行批处理文件 [英] execute a batch file from a program

查看:123
本文介绍了从程序执行批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从程序(EXE文件)执行批处理文件。我通常会创建批处理文件,而程序(EXE文件)执行。并且将在execl的(START,,NULL);

i would like to execute a batch file from a program (exe file). i usually create the batch file while program (exe file) execution. and will the execl("START","",NULL);

该功能调用批处理文件,但遗憾的是新的命令窗口中显示出来的execl的功能是流程启动并解析为CMD.EXE / K

the function is calling the batch file, but unfortunately new command window is showing up as the execl function is process START and parses as "cmd.exe /k " .

可以请你分享其中调用执行在后台批处理文件中的函数最简单的方法,如果可能的话请共享code片段。

can you please share the easiest way to call the function which executes the batch file in background, if possible please share the code snippet.

推荐答案

不要使用启动,但 CMD / C

ETA:正如评论克里斯小丑-Young指出,这会再像

ETA: As Chris Jester-Young notes in a comment, this will then look like

execlp("cmd", "/c", batchfile, static_cast<char*>(0))

在code。

ETA 2:看样子,你甚至不需要 CMD 那里。就在批处理文件的命令应该足够了。由于启动工作,启动是一个内置的命令的cmd.exe 必须的>为您的初始调用运行 CMD

ETA 2: It appears that you don't even need cmd there. Just the batch file as command should suffice. Since start worked and start is a built-in command of cmd.exe there has to be an instance of cmd running for your original invocation to work. So just execute the batch file as if it were the program, this should suffice.

这篇关于从程序执行批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆