windowsbatch-filesvnsvn-hookspost-commit

Running another program in Windows bat file and not create child process


I have subversion server with a post-commit hook to do something.

I want the checkin finish soon, not wait the hook script. But by design, the Subversion post-commit hook script will run until all child process exit, so using somthing like:

start another_prog...

in the hook bat file has no use.

So I want to know how to run another program in Windows bat file which not create child process or let the child process detach from the parent.


Solution

  • I found a method to resolve my question, compile the following c code and named the exe output as runjob.exe, and then in the hook bat file, use " runjob another_prog " , now it's ok.

    #include <windows.h> 
    #include <stdio.h> 
    #include <tchar.h> 
    int _tmain() 
    { 
        char * pCmd = ::GetCommandLine(); 
        // skip the executable 
        if (*pCmd++ == L'"')
        {
            while (*pCmd++ != L'"'); 
        }
        else 
        {
            while (*pCmd != NULL && *pCmd != L' ') 
                ++pCmd; 
        }
    
        while (*pCmd == L' ')
            pCmd++; 
    
        STARTUPINFO si; 
        ZeroMemory( &si, sizeof(si) ); 
        si.cb = sizeof(si); 
        PROCESS_INFORMATION pi; 
        ZeroMemory( &pi, sizeof(pi) ); 
    
        // Start the child process. 
        BOOL result = CreateProcess 
        ( 
            NULL, // No module name (use command line) 
            pCmd, // Command line 
            NULL, // Process handle not inheritable 
            NULL, // Thread handle not inheritable 
            FALSE, // Set bInheritHandles to FALSE 
            DETACHED_PROCESS, // Detach process 
            NULL, // Use parent's environment block 
            NULL, // Use parent's starting directory 
            &si, // Pointer to STARTUPINFO structure 
            &pi // Pointer to PROCESS_INFORMATION structure (returned) 
        ); 
        if (result) return 0; 
    
        char msg[2048]; 
        FormatMessage 
        ( 
            FORMAT_MESSAGE_FROM_SYSTEM, 
            NULL, 
            ::GetLastError(), 
            MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT), 
            msg, sizeof(msg), 
            NULL 
        ); 
        fputs(msg, stderr); 
        _flushall(); 
    
        return -1; 
    }