28#include <osl/process.h>
33#include <com/sun/star/util/PathSubstitution.hpp>
34#include <com/sun/star/util/XStringSubstitution.hpp>
45 return "com.sun.star.comp.framework.ShellJob";
68css::uno::Any SAL_CALL
ShellJob::execute(
const css::uno::Sequence< css::beans::NamedValue >& lJobArguments)
75 const css::uno::Sequence< OUString > lCommandArguments = lOwnCfg.
getUnpackedValueOrDefault(
"Arguments" , css::uno::Sequence< OUString >());
85 if (sRealCommand.isEmpty())
89 bool bDone =
impl_execute(sRealCommand, lCommandArguments, bCheckExitCode);
91 return css::uno::Any();
95 if (bDeactivateJobIfDone)
100 return css::uno::Any();
106 return css::uno::Any(aAnswer);
113 css::uno::Reference< css::util::XStringSubstitution > xSubst( css::util::PathSubstitution::create(
m_xContext) );
114 const bool bSubstRequired =
true;
115 const OUString sCompleteCommand = xSubst->substituteVariables(sCommand, bSubstRequired);
117 return sCompleteCommand;
119 catch(
const css::uno::Exception&)
126 const css::uno::Sequence< OUString >& lArguments ,
129 ::rtl_uString** pArgs =
nullptr;
130 const ::sal_Int32 nArgs = lArguments.getLength ();
131 oslProcess hProcess(
nullptr);
134 pArgs =
reinterpret_cast< ::rtl_uString**
>(
const_cast< OUString*
>(lArguments.getConstArray()));
136 oslProcessError eError = osl_executeProcess(sCommand.pData, pArgs, nArgs, osl_Process_WAIT,
nullptr,
nullptr,
nullptr, 0, &hProcess);
139 if (eError != osl_Process_E_None)
146 oslProcessInfo aInfo;
147 aInfo.Size =
sizeof (oslProcessInfo);
148 eError = osl_getProcessInfo(hProcess, osl_Process_EXITCODE, &aInfo);
150 if (eError != osl_Process_E_None)
153 bRet = (aInfo.Code == 0);
155 osl_freeProcessHandle(hProcess);
161extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
163 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const& )
constexpr OUStringLiteral sServiceName
TValueType getUnpackedValueOrDefault(const OUString &sKey, const TValueType &aDefault) const
static constexpr OUStringLiteral ANSWER_DEACTIVATE_JOB
implements a job component which can be used to execute system shell commands.
css::uno::Reference< css::uno::XComponentContext > m_xContext
reference to a uno service manager.
ShellJob(css::uno::Reference< css::uno::XComponentContext > xContext)
create new instance of this class.
OUString impl_substituteCommandVariables(const OUString &sCommand)
substitute all might existing placeholder variables within the configured command.
virtual ~ShellJob() override
does nothing real ...
virtual sal_Bool SAL_CALL supportsService(const OUString &sServiceName) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
bool impl_execute(const OUString &sCommand, const css::uno::Sequence< OUString > &lArguments, bool bCheckExitCode)
executes the command.
static css::uno::Any impl_generateAnswer4Deactivation()
generate a return value for method execute() which will force deactivation of this job for further re...
virtual css::uno::Any SAL_CALL execute(const css::uno::Sequence< css::beans::NamedValue > &lArguments) override
virtual OUString SAL_CALL getImplementationName() override
css::uno::Reference< css::uno::XComponentContext > m_xContext
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
constexpr OUStringLiteral SERVICENAME_JOB
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * framework_ShellJob_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)