使用createProcess()运行批处理文件 [英] Run a batch file using createProcess()

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

问题描述

是否有必要按照文档中所述将lpApplicationName设置为cmd.exe来运行批处理文件?

Is it necessary to set lpApplicationName to cmd.exe as mentioned in the documentation to run a batch file?

  • 端口= 5598 dbname =演示主机=本地主机"
  • 端口= 5599 dbname =演示主机=本地主机"
  • "C:/tmp/000002AB-1.16432"
  • "C:/bin/pg_restore.exe"

假定批处理文件的路径为"C:/Users/abc.bat".如何将上述字符串作为参数传递给批处理文件?

Assume that the path of the batch file is "C:/Users/abc.bat". How can i pass the above strings are to be passed as arguments to the batch file?

推荐答案

假设采用标准配置,答案是否定的,不是必需的.您可以将批处理文件包含在 lpCommandLine 参数中.其余参数仅在批处理文件之后,并在需要的地方加上引号.

Assumming a standard configuration, the answer is no, it is not required. You can include the batch file in the lpCommandLine argument. The remaining arguments just follow the batch file with quotes where needed.

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

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

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