JAVA如何使用CreateProcess函数

时间:2017-09-21 17:17:02

标签: java

这就是我从C ++那里得到的

String pathexe = "C:\Windows\system32\cmd.exe";
String command= "notepad.exe";

if(!CreateProcess(
        pathexe.c_str(),  // lpApplicationName
        command.c_str(),  // lpCommandLine
        NULL,   // lpProcessAttributes
        NULL,   // lpThreadAttributes
        FALSE,  // bInheritHandles
        0,      // dwCreationFlags
        NULL,   // lpEnvironment
        NULL,   // lpCurrentDirectory
        &si,    // lpStartupInfo
        &pi     // lpProcessInformation
        ))

我试图搜索JAVA语言中使用的CreateProcess,JAVA是否可以使用CreateProcess?

我需要lpProcessInformation.hThread& lpProcessInformation.hProcess返回值。

1 个答案:

答案 0 :(得分:0)

尝试RuntimeProcess对象。

    Process p = Runtime.getRuntime().exec("cmd.exe /c start dir ");
    BufferedWriter writeer = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
    writeer.write("dir");
    writeer.flush();
    BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
    BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));

    // read output of ur commaand