2016-11-17 193 views
0

是否需要將lpApplicationName設置爲cmd.exe,如文檔中提到的那樣運行批處理文件?使用createProcess()運行批處理文件()

  • 「端口= 5598 DBNAME =演示主機=本地主機」
  • 「端口= 5599 DBNAME =演示主機=本地主機」
  • 「C:/tmp/000002AB-1.16432」
  • 「C: /bin/pg_restore.exe「

假設批處理文件的路徑是」C:/Users/abc.bat「。 我怎樣才能傳遞上述字符串作爲參數傳遞給批處理文件?

回答

1

假設一個標準配置,答案是否定的,它不是要求。您可以將該批處理文件包含在lpCommandLine參數中。其餘的參數只是在需要的地方用引號引用批處理文件。

TEST.CMD

@echo off 
    setlocal enableextensions disabledelayedexpansion 
    echo %1 
    echo %~1 
    echo %2 
    echo %~2 

test.c的

#define _WIN32_WINNT 0x0500 
#include <windows.h> 

void main(void){ 

    // Spawn process variables 
    STARTUPINFO si; 
    PROCESS_INFORMATION pi; 

    ZeroMemory(&si, sizeof(si)); 
    si.cb = sizeof(si); 
    ZeroMemory(&pi, sizeof(pi)); 

    CreateProcess(
     NULL 
     , "\"test.cmd\" \"x=1 y=2\" \"x=3 y=4\"" 
     , NULL 
     , NULL 
     , TRUE 
     , 0 
     , NULL 
     , NULL 
     , &si 
     , &pi 
    ); 

    WaitForSingleObject(pi.hProcess, INFINITE); 
    CloseHandle(pi.hProcess); 
    CloseHandle(pi.hThread);  
}; 

輸出

W:\>test.exe 
"x=1 y=2" 
x=1 y=2 
"x=3 y=4" 
x=3 y=4