繁体   English   中英

在 C 程序中打开批处理文件 (.bat)?

[英]Opening a batch file (.bat) in a C program?

如何从我的 C 程序开始运行批处理文件 (.bat)? 我用了

system("start /B omanam.bat");

但它不起作用。 如何make.bat通过C打开?

放下start 这是一个 cmd.exe 的东西。 只需运行system("omanam.bat"); .

如果您的 C 可执行程序和批处理文件在同一目录中,则

system("batchfilename.bat arg1 arg2");

其中arg1arg2是此批处理文件的 arguments。


如果批处理文件在另一个目录中

 system("f:\\bin\\batchfilename.bat arg1 arg2");

其中arg1arg2是此批处理文件的 arguments。


C 代码:

#include <stdio.h>
#include <stdlib.h>

int main()
{

  printf("Calling batch file doit.bat\n");
  system("doit Hello. theansweris: 42");
  printf("Press \'Enter\' to exit the program\n");
  getchar();
  return 0;
}

批处理文件代码:

@rem This is the batch file doit.bat
@echo.
@echo.
@echo.
@echo In doit.bat:
@echo.
@echo.
@echo.
@echo argument #1 is ^"%1^"
@echo argument #2 is ^"%2^"
@echo argument #3 is ^"%3^"
@echo.
@echo.
@echo Tttttthat's all, folks!
@echo.
@echo.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM