簡體   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