Domanda

Ho server Subversion con un post-commit hook di fare qualcosa.

Voglio che il traguardo di arrivo presto, non aspettare lo script gancio. Ma in base alla progettazione, il post-commit Subversion script di hook verrà eseguito fino a quando tutto bambina di uscita del processo, in modo da utilizzare somthing come:

iniziare another_prog ...

nel file gancio pipistrello non ha alcun uso.

Quindi vorrei sapere come far funzionare un altro programma in file bat Windows, che non crea processo figlio o lasciare che il processo figlio staccarsi dal genitore.

È stato utile?

Soluzione 2

Ho trovato un metodo per risolvere la mia domanda, compilare il seguente codice C e chiamato l'uscita exe come runjob.exe, e poi nel file gancio pipistrello, usare "runjob another_prog", ora è 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; 
} 

Altri suggerimenti

sincrono. Il secondo blocco note non si avvia finché non si chiude la prima.

notepad.exe c:\temp\a.txt
notepad.exe c:\temp\b.txt

asincrona:. Il secondo blocco note lancerà anche se non si è chiuso il primo

start notepad.exe c:\temp\a.txt
start notepad.exe c:\temp\b.txt

Maggiori informazioni sul comando di avvio:
http://www.robvanderwoude.com/ntstart.php

Modifica : Il seguente commento è stato fatto altrove dal @zhongshu, il manifesto originale. Sono solo la copia qui:

  

start cmd / c non funziona perché SVN   post-commit hook attenderà il   gancio e il processo figlio creato da   l'uscita gancio. E 'la progettazione di SVN.   Ho trovato una soluzione, fare riferimento:    http://svn.haxx.se/users/archive-2008-11 /0301.shtml

Supponendo che egli sa di cosa sta parlando, mi sbaglio e ... immeritevole.

Che cosa si può fare è di creare un'attività pianificata che esegue lo script batch o altro eseguibile che viene eseguito per molto tempo. Impostare per eseguire una volta, in passato, e non impostarlo per eliminare l'attività quando non più corse sono in programma. Poi nello script hook Subversion, inserire la seguente riga in:

schtasks /run /tn NameOfYourTaskHere

Ho confermato con un test da avere il mio programma Notepad ++ esecuzione dell'attività e l'eseguibile Notepad ++ si presentò come figlio di svchost.exe, non la finestra cmd.exe che ho eseguito il comando schtasks da.

Usa:

start cmd /c "your command"

Saluti.

Prova cmd /c "your command"

Potresti utilizzare l'interfaccia a riga di comando pianificazione di Windows "schtasks / run" per avviare un lavoro che gestisce il "another_prog"? Avresti per creare il lavoro prima del tempo. C'è anche usato per essere un "presto" programma con Windows (NT) Resource Kit che creerebbe voci dinamiche per il comando "AT" scheduler per eseguire un lavoro in pochi minuti, che non richiederebbero la creazione di un posto di lavoro prima del tempo, si può ancora essere trovato con un po 'di ricerca.

È possibile creare un file batch di ibrido / JScript (cioè un file batch in grado di eseguire JScript incorporato) dove la parte JScript verrà eseguito another_prog in modalità indipendente con shell.Run (prog, 0, false) :

@if (@X)==(@Y) @end /* JScript comment
    rem put any batch code that runs before another_prog here
    @cscript //E:JScript //nologo "%~f0" "another_prog" 0 false
    rem put any batch code that runs after another_prog here

    exit /b %errorlevel%
@if (@X)==(@Y) @end JScript comment */

var ARGS = WScript.Arguments;
var shell = new ActiveXObject("WScript.Shell");
shell.Run(ARGS.Item(0),ARGS.Item(1),ARGS.Item(2));`
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top