Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jar服务器停止触发shutdown.exe < >我想编写一个C++代码来启动java服务器(文件名是Server .jar),当服务器停止时,我想运行SutnD.EXE。 我查找了如何启动server.jar,但没有找到任何关于如何检测它停止的可理解的内容_C++_Windows_Jar_Shutdown - Fatal编程技术网

jar服务器停止触发shutdown.exe < >我想编写一个C++代码来启动java服务器(文件名是Server .jar),当服务器停止时,我想运行SutnD.EXE。 我查找了如何启动server.jar,但没有找到任何关于如何检测它停止的可理解的内容

jar服务器停止触发shutdown.exe < >我想编写一个C++代码来启动java服务器(文件名是Server .jar),当服务器停止时,我想运行SutnD.EXE。 我查找了如何启动server.jar,但没有找到任何关于如何检测它停止的可理解的内容,c++,windows,jar,shutdown,C++,Windows,Jar,Shutdown,我想要实现的是: 运行脚本-->服务器启动并运行一段时间 服务器从客户端接收停止命令 服务器停止-->脚本运行shutdown.exe 我使代码正常工作,因此: #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <string> #include <windows.h> #include <stdlib.h> int main() { STARTUPINFO info = {

我想要实现的是:

  • 运行脚本-->服务器启动并运行一段时间
  • 服务器从客户端接收停止命令
  • 服务器停止-->脚本运行shutdown.exe

  • 我使代码正常工作,因此:

    #define _CRT_SECURE_NO_WARNINGS
    #include <iostream>
    #include <string>
    #include <windows.h>
    #include <stdlib.h>
    
    int main() {
    STARTUPINFO info = { sizeof(info) };
    PROCESS_INFORMATION processInfo;
    wchar_t cmdline[] = L" -jar server.jar";
    //wchar_t path[] = L"C:\\Program Files\\Java\\jre*\\bin\\javaw.exe";
    
    char* pathc= std::getenv("_JAVAW");
    wchar_t* path;
    path = (wchar_t*)malloc(sizeof(wchar_t) * strlen(pathc));
    mbstowcs(path, pathc, strlen(pathc)+1);
    
    if (CreateProcess( path, cmdline, NULL, NULL, TRUE, 0, NULL, NULL, &info, &processInfo))
    {
        std::cout << "running" << std::endl;
        WaitForSingleObject(processInfo.hProcess, INFINITE);
        wchar_t cmdline[] = L" -s -t 60";
        CloseHandle(processInfo.hProcess);
        CloseHandle(processInfo.hThread);
        if (CreateProcess(L"C:\\WINDOWS\\system32\\shutdown.exe", cmdline, NULL, NULL, TRUE, 0, NULL, NULL, &info, &processInfo)) {
    
        }
        WaitForSingleObject(processInfo.hProcess, INFINITE);
        CloseHandle(processInfo.hProcess);
        CloseHandle(processInfo.hThread);
    }
    return 0;
    
    \define\u CRT\u SECURE\u NO\u警告
    #包括
    #包括
    #包括
    #包括
    int main(){
    STARTUPINFO={sizeof(info)};
    处理信息处理信息;
    wchar_t cmdline[]=L“-jar server.jar”;
    //wchar\u t path[]=L“C:\\Program Files\\Java\\jre*\\bin\\javaw.exe”;
    char*pathc=std::getenv(“_JAVAW”);
    wchar_t*路径;
    路径=(wchar_t*)malloc(sizeof(wchar_t)*strlen(pathc));
    mbstowcs(路径、路径C、strlen(路径C)+1);
    if(CreateProcess(path、cmdline、NULL、NULL、TRUE、0、NULL、NULL、info和processInfo))
    {
    标准::cout