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