sl@0: // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Perl.cpp: allows running of a perl script and waiting for its completion. sl@0: // sl@0: sl@0: #include "stdafx.h" sl@0: sl@0: #include "usbio.h" // USBIO Dev Kit sl@0: sl@0: #ifdef _DEBUG sl@0: #undef THIS_FILE sl@0: static char THIS_FILE[]=__FILE__; sl@0: #define new DEBUG_NEW sl@0: #endif sl@0: sl@0: // define the CreateProcess strings for Perl sl@0: #define APPNAME "C:\\Apps\\Perl\\Bin\\Perl.exe" sl@0: #define APPTITLE "Perl Script" sl@0: sl@0: #define WAIT_SLEEP 1000 // checks for for perl script completion every second sl@0: #define EXIT_WAIT 900 // exits if not complete within 15 minutes sl@0: sl@0: sl@0: DWORD PerlScript(char * scriptName) sl@0: { sl@0: STARTUPINFO si; sl@0: PROCESS_INFORMATION pi; sl@0: DWORD exitCode = STILL_ACTIVE; sl@0: sl@0: ZeroMemory( &si, sizeof(si) ); sl@0: si.cb = sizeof(si); sl@0: ZeroMemory( &pi, sizeof(pi) ); sl@0: sl@0: if (!CreateProcess (APPNAME,scriptName,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi)) sl@0: return USBIO_ERR_INVALID_PROCESS; sl@0: sl@0: for (int i = 0; i < EXIT_WAIT && exitCode == STILL_ACTIVE; i++) sl@0: { sl@0: Sleep (WAIT_SLEEP); sl@0: GetExitCodeProcess(pi.hProcess,(LPDWORD)&exitCode); sl@0: } sl@0: sl@0: // Force an unclean process termination only if necessary sl@0: if (exitCode == STILL_ACTIVE) sl@0: { sl@0: TerminateProcess(pi.hProcess,0); sl@0: return USBIO_ERR_TIMEOUT; sl@0: } sl@0: sl@0: return exitCode; sl@0: } sl@0: