1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/usb/t_usb_win/src/Perl.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,63 @@
1.4 +// Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Perl.cpp: allows running of a perl script and waiting for its completion.
1.18 +//
1.19 +
1.20 +#include "stdafx.h"
1.21 +
1.22 +#include "usbio.h" // USBIO Dev Kit
1.23 +
1.24 +#ifdef _DEBUG
1.25 +#undef THIS_FILE
1.26 +static char THIS_FILE[]=__FILE__;
1.27 +#define new DEBUG_NEW
1.28 +#endif
1.29 +
1.30 +// define the CreateProcess strings for Perl
1.31 +#define APPNAME "C:\\Apps\\Perl\\Bin\\Perl.exe"
1.32 +#define APPTITLE "Perl Script"
1.33 +
1.34 +#define WAIT_SLEEP 1000 // checks for for perl script completion every second
1.35 +#define EXIT_WAIT 900 // exits if not complete within 15 minutes
1.36 +
1.37 +
1.38 +DWORD PerlScript(char * scriptName)
1.39 +{
1.40 + STARTUPINFO si;
1.41 + PROCESS_INFORMATION pi;
1.42 + DWORD exitCode = STILL_ACTIVE;
1.43 +
1.44 + ZeroMemory( &si, sizeof(si) );
1.45 + si.cb = sizeof(si);
1.46 + ZeroMemory( &pi, sizeof(pi) );
1.47 +
1.48 + if (!CreateProcess (APPNAME,scriptName,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi))
1.49 + return USBIO_ERR_INVALID_PROCESS;
1.50 +
1.51 + for (int i = 0; i < EXIT_WAIT && exitCode == STILL_ACTIVE; i++)
1.52 + {
1.53 + Sleep (WAIT_SLEEP);
1.54 + GetExitCodeProcess(pi.hProcess,(LPDWORD)&exitCode);
1.55 + }
1.56 +
1.57 + // Force an unclean process termination only if necessary
1.58 + if (exitCode == STILL_ACTIVE)
1.59 + {
1.60 + TerminateProcess(pi.hProcess,0);
1.61 + return USBIO_ERR_TIMEOUT;
1.62 + }
1.63 +
1.64 + return exitCode;
1.65 +}
1.66 +