2000-09-18 15:18:56 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-11 10:38:56 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2008-04-11 10:38:56 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2008-04-11 10:38:56 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2008-04-11 10:38:56 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2008-04-11 10:38:56 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2008-04-11 10:38:56 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-17 08:57:38 +00:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_basic.hxx"
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
#ifdef WNT
|
|
|
|
#include <tools/prewin.h>
|
|
|
|
#include "winbase.h"
|
|
|
|
#include <tools/postwin.h>
|
|
|
|
#endif
|
|
|
|
#include <tools/errcode.hxx>
|
|
|
|
#include <vos/process.hxx>
|
2007-06-27 13:15:52 +00:00
|
|
|
#include <basic/sbxcore.hxx>
|
2000-09-18 15:18:56 +00:00
|
|
|
#include <tools/string.hxx>
|
|
|
|
#include <osl/file.hxx>
|
|
|
|
|
|
|
|
#ifndef _BASIC_TTRESHLP_HXX
|
2007-06-27 13:15:52 +00:00
|
|
|
#include <basic/ttstrhlp.hxx>
|
2000-09-18 15:18:56 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
//#ifndef _BYTE_STRING_LIST
|
|
|
|
//DECLARE_LIST( ByteStringList, ByteString * );
|
|
|
|
//#define _BYTE_STRING_LIST
|
|
|
|
//#endif
|
|
|
|
|
2007-06-27 13:15:52 +00:00
|
|
|
#include <basic/process.hxx>
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
Process::Process()
|
2006-06-19 16:37:17 +00:00
|
|
|
: pArgumentList( NULL )
|
2004-06-17 10:47:29 +00:00
|
|
|
, pEnvList( NULL )
|
2000-09-18 15:18:56 +00:00
|
|
|
, pProcess( NULL )
|
2006-06-19 16:37:17 +00:00
|
|
|
, bWasGPF( FALSE )
|
2000-09-18 15:18:56 +00:00
|
|
|
, bHasBeenStarted( FALSE )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Process::~Process()
|
|
|
|
{
|
2004-06-17 10:47:29 +00:00
|
|
|
// delete pArgumentList;
|
|
|
|
// delete pEnvList;
|
2000-09-18 15:18:56 +00:00
|
|
|
delete pProcess;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOL Process::ImplIsRunning()
|
|
|
|
{
|
|
|
|
if ( pProcess && bHasBeenStarted )
|
|
|
|
{
|
2010-07-01 09:13:15 +02:00
|
|
|
vos::OProcess::TProcessInfo aProcessInfo;
|
|
|
|
pProcess->getInfo( vos::OProcess::TData_ExitCode, &aProcessInfo );
|
|
|
|
if ( !(aProcessInfo.Fields & vos::OProcess::TData_ExitCode) )
|
2000-09-18 15:18:56 +00:00
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
long Process::ImplGetExitCode()
|
|
|
|
{
|
|
|
|
if ( pProcess )
|
|
|
|
{
|
2010-07-01 09:13:15 +02:00
|
|
|
vos::OProcess::TProcessInfo aProcessInfo;
|
|
|
|
pProcess->getInfo( vos::OProcess::TData_ExitCode, &aProcessInfo );
|
|
|
|
if ( !(aProcessInfo.Fields & vos::OProcess::TData_ExitCode) )
|
2000-09-18 15:18:56 +00:00
|
|
|
SbxBase::SetError( SbxERR_NO_ACTIVE_OBJECT );
|
|
|
|
return aProcessInfo.Code;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
SbxBase::SetError( SbxERR_NO_ACTIVE_OBJECT );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2004-06-17 10:47:29 +00:00
|
|
|
void Process::SetImage( const String &aAppPath, const String &aAppParams, const Environment *pEnv )
|
2009-04-25 00:18:20 +00:00
|
|
|
{ // Set image file of executable
|
2000-09-18 15:18:56 +00:00
|
|
|
if ( pProcess && ImplIsRunning() )
|
|
|
|
SbxBase::SetError( SbxERR_NO_ACTIVE_OBJECT );
|
|
|
|
else
|
|
|
|
{
|
2004-06-17 10:47:29 +00:00
|
|
|
delete pArgumentList; pArgumentList = NULL;
|
|
|
|
delete pEnvList; pEnvList = NULL;
|
|
|
|
delete pProcess; pProcess = NULL;
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
xub_StrLen i, nCount = aAppParams.GetQuotedTokenCount( CUniString("\"\"" ), ' ' );
|
2001-03-21 14:07:28 +00:00
|
|
|
::rtl::OUString *pParamList = new ::rtl::OUString[nCount];
|
2003-03-26 11:04:51 +00:00
|
|
|
|
|
|
|
xub_StrLen nParamCount = 0;
|
2000-09-18 15:18:56 +00:00
|
|
|
for ( i = 0 ; i < nCount ; i++ )
|
|
|
|
{
|
2003-03-26 11:04:51 +00:00
|
|
|
::rtl::OUString aTemp = ::rtl::OUString(aAppParams.GetQuotedToken( i, CUniString("\"\"''" ), ' ' ));
|
2000-09-18 15:18:56 +00:00
|
|
|
if ( aTemp.getLength() )
|
2003-03-26 11:04:51 +00:00
|
|
|
{
|
|
|
|
pParamList[nParamCount] = aTemp;
|
|
|
|
nParamCount++;
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
2010-07-01 09:13:15 +02:00
|
|
|
pArgumentList = new vos::OArgumentList( pParamList, nCount );
|
2004-06-17 10:47:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
::rtl::OUString *pEnvArray = NULL;
|
|
|
|
if ( pEnv )
|
|
|
|
{
|
2006-10-12 13:23:06 +00:00
|
|
|
pEnvArray = new ::rtl::OUString[pEnv->size()];
|
2004-06-17 10:47:29 +00:00
|
|
|
|
|
|
|
xub_StrLen nEnvCount = 0;
|
|
|
|
Environment::const_iterator aIter = pEnv->begin();
|
|
|
|
while ( aIter != pEnv->end() )
|
|
|
|
{
|
|
|
|
::rtl::OUString aTemp = ::rtl::OUString( (*aIter).first );
|
|
|
|
aTemp += ::rtl::OUString::createFromAscii( "=" );
|
|
|
|
aTemp += ::rtl::OUString( (*aIter).second );
|
|
|
|
pEnvArray[nEnvCount] = aTemp;
|
|
|
|
nEnvCount++;
|
|
|
|
aIter++;
|
|
|
|
}
|
2010-07-01 09:13:15 +02:00
|
|
|
pEnvList = new vos::OEnvironment( pEnvArray, nEnvCount );
|
2004-06-17 10:47:29 +00:00
|
|
|
}
|
|
|
|
|
2001-03-21 14:07:28 +00:00
|
|
|
::rtl::OUString aNormalizedAppPath;
|
2001-05-10 14:59:46 +00:00
|
|
|
osl::FileBase::getFileURLFromSystemPath( ::rtl::OUString(aAppPath), aNormalizedAppPath );
|
2010-07-01 09:13:15 +02:00
|
|
|
pProcess = new vos::OProcess( aNormalizedAppPath );
|
2000-09-18 15:18:56 +00:00
|
|
|
bHasBeenStarted = FALSE;
|
2003-05-22 10:01:04 +00:00
|
|
|
|
|
|
|
delete [] pParamList;
|
2004-06-17 10:47:29 +00:00
|
|
|
delete [] pEnvArray;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL Process::Start()
|
2009-04-25 00:18:20 +00:00
|
|
|
{ // Start program
|
2000-09-18 15:18:56 +00:00
|
|
|
BOOL bSuccess=FALSE;
|
|
|
|
if ( pProcess && !ImplIsRunning() )
|
|
|
|
{
|
|
|
|
bWasGPF = FALSE;
|
|
|
|
#ifdef WNT
|
|
|
|
// sal_uInt32 nErrorMode = SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_NOALIGNMENTFAULTEXCEPT | SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
|
|
|
|
sal_uInt32 nErrorMode = SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_NOALIGNMENTFAULTEXCEPT | SEM_NOGPFAULTERRORBOX);
|
|
|
|
try
|
|
|
|
{
|
|
|
|
#endif
|
2004-06-17 10:47:29 +00:00
|
|
|
if ( pEnvList )
|
|
|
|
{
|
2010-07-01 09:13:15 +02:00
|
|
|
bSuccess = pProcess->execute( (vos::OProcess::TProcessOption)
|
|
|
|
( vos::OProcess::TOption_SearchPath
|
|
|
|
/*| vos::OProcess::TOption_Detached*/
|
|
|
|
/*| vos::OProcess::TOption_Wait*/ ),
|
2004-06-17 10:47:29 +00:00
|
|
|
*pArgumentList,
|
2010-07-01 09:13:15 +02:00
|
|
|
*pEnvList ) == vos::OProcess::E_None;
|
2004-06-17 10:47:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-07-01 09:13:15 +02:00
|
|
|
bSuccess = pProcess->execute( (vos::OProcess::TProcessOption)
|
|
|
|
( vos::OProcess::TOption_SearchPath
|
|
|
|
/*| vos::OProcess::TOption_Detached*/
|
|
|
|
/*| vos::OProcess::TOption_Wait*/ ),
|
|
|
|
*pArgumentList ) == vos::OProcess::E_None;
|
2004-06-17 10:47:29 +00:00
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
#ifdef WNT
|
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
|
|
|
bWasGPF = TRUE;
|
2009-04-25 00:18:20 +00:00
|
|
|
// TODO: Output debug message !!
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
nErrorMode = SetErrorMode(nErrorMode);
|
|
|
|
#endif
|
|
|
|
bHasBeenStarted = bSuccess;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
SbxBase::SetError( SbxERR_NO_ACTIVE_OBJECT );
|
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG Process::GetExitCode()
|
2009-04-25 00:18:20 +00:00
|
|
|
{ // ExitCode of program after execution
|
2000-09-18 15:18:56 +00:00
|
|
|
return ImplGetExitCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL Process::IsRunning()
|
2009-04-25 00:18:20 +00:00
|
|
|
{
|
2000-09-18 15:18:56 +00:00
|
|
|
return ImplIsRunning();
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL Process::WasGPF()
|
2009-04-25 00:18:20 +00:00
|
|
|
{ // Did the process fail?
|
2000-09-18 15:18:56 +00:00
|
|
|
#ifdef WNT
|
|
|
|
return ImplGetExitCode() == 3221225477;
|
|
|
|
#else
|
|
|
|
return bWasGPF;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2004-09-20 11:29:06 +00:00
|
|
|
BOOL Process::Terminate()
|
|
|
|
{
|
|
|
|
if ( ImplIsRunning() )
|
|
|
|
return pProcess->terminate() == vos::OProcess::E_None;
|
2005-06-21 09:30:46 +00:00
|
|
|
return TRUE;
|
2004-09-20 11:29:06 +00:00
|
|
|
}
|
|
|
|
|