os/kernelhwsrv/kerneltest/e32test/usb/t_usb_win/src/Perl.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Perl.cpp: allows running of a perl script and waiting for its completion.
    15 //
    16 
    17 #include "stdafx.h"
    18 
    19 #include "usbio.h"											// USBIO Dev Kit
    20 
    21 #ifdef _DEBUG
    22 #undef THIS_FILE
    23 static char THIS_FILE[]=__FILE__;
    24 #define new DEBUG_NEW
    25 #endif
    26 
    27 // define the CreateProcess strings for Perl
    28 #define APPNAME "C:\\Apps\\Perl\\Bin\\Perl.exe"
    29 #define APPTITLE "Perl Script"
    30 
    31 #define WAIT_SLEEP 1000			// checks for for perl script completion every second		
    32 #define EXIT_WAIT 900			// exits if not complete within 15 minutes
    33 
    34 
    35 DWORD PerlScript(char * scriptName)
    36 {
    37     STARTUPINFO si;
    38     PROCESS_INFORMATION pi;
    39 	DWORD exitCode = STILL_ACTIVE;
    40 
    41     ZeroMemory( &si, sizeof(si) );
    42     si.cb = sizeof(si);
    43     ZeroMemory( &pi, sizeof(pi) );
    44 
    45 	if (!CreateProcess (APPNAME,scriptName,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi))
    46 		return USBIO_ERR_INVALID_PROCESS;
    47 
    48 	for (int i = 0; i < EXIT_WAIT && exitCode == STILL_ACTIVE; i++)
    49 		{
    50 		Sleep (WAIT_SLEEP);
    51 		GetExitCodeProcess(pi.hProcess,(LPDWORD)&exitCode);
    52 		}
    53 	
    54 	// Force an unclean process termination only if necessary
    55 	if (exitCode == STILL_ACTIVE)
    56 		{
    57 		TerminateProcess(pi.hProcess,0);
    58 		return USBIO_ERR_TIMEOUT;
    59 		}
    60 
    61 	return exitCode;
    62 }
    63