Repository.mk | 2 sal/Executable_executeprocess.mk | 31 ++++++++++++ sal/Executable_processcmdlineargs.mk | 31 ++++++++++++ sal/Module_sal.mk | 2 sal/workben/osl/batch.bat | 19 +++++++ sal/workben/osl/batch.sh | 2 sal/workben/osl/executeprocess.cxx | 83 +++++++++++++++++++++++++++++++++ sal/workben/osl/processcmdlineargs.cxx | 75 +++++++++++++++++++++++++++++ 8 files changed, 245 insertions(+)
New commits: commit cd2179ddb6f7f88b67c5ad9a0a0ff919c93606b4 Author: Chris Sherlock <chris.sherloc...@gmail.com> Date: Sun Jul 30 01:31:11 2017 +1000 sal workben: Demonstrate osl_executeProcess() Change-Id: I7b6e3d89601b78deec7e78f5817a4980b4007ebf diff --git a/Repository.mk b/Repository.mk index f82bfed6ba51..8413facda420 100644 --- a/Repository.mk +++ b/Repository.mk @@ -83,6 +83,7 @@ $(eval $(call gb_Helper_register_executables,NONE, \ processworkdir \ getprocessinfo \ processcmdlineargs \ + executeprocess \ )) $(eval $(call gb_Helper_register_executables_for_install,SDK,sdk, \ diff --git a/sal/Executable_executeprocess.mk b/sal/Executable_executeprocess.mk new file mode 100644 index 000000000000..7294ab0e8745 --- /dev/null +++ b/sal/Executable_executeprocess.mk @@ -0,0 +1,31 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_Executable_Executable,executeprocess)) + +$(eval $(call gb_Executable_set_include,executeprocess,\ + $$(INCLUDE) \ + -I$(SRCDIR)/sal/inc \ +)) + +$(eval $(call gb_Library_add_defs,executeprocess,\ + -DSAL_DLLIMPLEMENTATION \ +)) + +$(eval $(call gb_Executable_use_libraries,executeprocess,\ + sal \ +)) + +$(eval $(call gb_Executable_add_exception_objects,executeprocess,\ + sal/workben/osl/executeprocess \ +)) + +$(call gb_Executable_get_clean_target,executeprocess) : + rm -f $(WORKDIR)/LinkTarget/Executable/executeprocess +# vim: set ts=4 sw=4 et: diff --git a/sal/Module_sal.mk b/sal/Module_sal.mk index 95f88ffbd1ef..4f6118210247 100644 --- a/sal/Module_sal.mk +++ b/sal/Module_sal.mk @@ -28,6 +28,7 @@ $(eval $(call gb_Module_add_targets,sal,\ Executable_processworkdir \ Executable_getprocessinfo \ Executable_processcmdlineargs \ + Executable_executeprocess \ )) $(eval $(call gb_Module_add_check_targets,sal,\ diff --git a/sal/workben/osl/batch.bat b/sal/workben/osl/batch.bat new file mode 100755 index 000000000000..e27f7191bfc2 --- /dev/null +++ b/sal/workben/osl/batch.bat @@ -0,0 +1,19 @@ +rem +rem This file is part of the LibreOffice project. +rem +rem This Source Code Form is subject to the terms of the Mozilla Public +rem License, v. 2.0. If a copy of the MPL was not distributed with this +rem file, You can obtain one at http://mozilla.org/MPL/2.0/. +rem +rem This file incorporates work covered by the following license notice: +rem +rem Licensed to the Apache Software Foundation (ASF) under one or more +rem contributor license agreements. See the NOTICE file distributed +rem with this work for additional information regarding copyright +rem ownership. The ASF licenses this file to you under the Apache +rem License, Version 2.0 (the "License"); you may not use this file +rem except in compliance with the License. You may obtain a copy of +rem the License at http://www.apache.org/licenses/LICENSE-2.0 . +rem +@echo off +echo "Hello world" \ No newline at end of file diff --git a/sal/workben/osl/batch.sh b/sal/workben/osl/batch.sh new file mode 100755 index 000000000000..fd3828c6ae42 --- /dev/null +++ b/sal/workben/osl/batch.sh @@ -0,0 +1,2 @@ +#!/bin/sh +echo "Hello world" \ No newline at end of file diff --git a/sal/workben/osl/executeprocess.cxx b/sal/workben/osl/executeprocess.cxx new file mode 100644 index 000000000000..5e925e8defc4 --- /dev/null +++ b/sal/workben/osl/executeprocess.cxx @@ -0,0 +1,83 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/config.h> +#include <sal/main.h> +#include <sal/log.hxx> +#include <rtl/ustring.hxx> +#include <rtl/alloc.h> +#include <osl/thread.h> +#include <osl/file.h> + +#include <osl/process.h> + +#include <cstdio> + +SAL_IMPLEMENT_MAIN() +{ + oslProcess aProcess; + + fprintf(stdout, "Execute process.\n"); + + rtl_uString *pustrExePath = nullptr; + osl_getExecutableFile(&pustrExePath); + + rtl_uString *pTempExePath = nullptr; + sal_uInt32 nLastChar; + + nLastChar = rtl_ustr_lastIndexOfChar(rtl_uString_getStr(pustrExePath), SAL_PATHDELIMITER); + rtl_uString_newReplaceStrAt(&pTempExePath, pustrExePath, nLastChar, rtl_ustr_getLength(rtl_uString_getStr(pustrExePath)), nullptr); + rtl_freeMemory(pustrExePath); + pustrExePath = pTempExePath; + +#if defined(_WIN32) +# define BATCHFILE "\\..\\sal\\workben\\osl\\batch.bat" +# define BATCHFILE_LENGTH 35 +#else +# define BATCHFILE "/../../../sal/workben/osl/batch.sh" +# define BATCHFILE_LENGTH 34 +#endif + + rtl_uString_newConcatAsciiL(&pustrExePath, pustrExePath, BATCHFILE, BATCHFILE_LENGTH); + + oslProcessError osl_error = osl_executeProcess( + pustrExePath, // process to execute + nullptr, // no arguments + 0, // no arguments + osl_Process_NORMAL, // process execution mode + nullptr, // security context is current user + nullptr, // current working directory inherited from parent process + nullptr, // no environment variables + 0, // no environment variables + &aProcess); // process handle + + rtl_freeMemory(pustrExePath); + + if (osl_error != osl_Process_E_None) + fprintf(stderr, "Process failed\n"); + + fprintf(stdout, " Process running...\n"); + osl_joinProcess(aProcess); + fprintf(stdout, " ...process finished.\n"); + osl_freeProcessHandle(aProcess); + + return 0; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit ed451866d54cde546bccaa6c9af0008dedbcb0b6 Author: Chris Sherlock <chris.sherloc...@gmail.com> Date: Sat Jul 29 22:46:20 2017 +1000 sal workben: add osl_getCommandArg() and osl_getCommandArgCount() Change-Id: I624b5454c5e8f86997b35ffc3f8680e353f48006 diff --git a/Repository.mk b/Repository.mk index 453fc95c8066..f82bfed6ba51 100644 --- a/Repository.mk +++ b/Repository.mk @@ -82,6 +82,7 @@ $(eval $(call gb_Helper_register_executables,NONE, \ config \ processworkdir \ getprocessinfo \ + processcmdlineargs \ )) $(eval $(call gb_Helper_register_executables_for_install,SDK,sdk, \ diff --git a/sal/Executable_processcmdlineargs.mk b/sal/Executable_processcmdlineargs.mk new file mode 100644 index 000000000000..ca60c94fb031 --- /dev/null +++ b/sal/Executable_processcmdlineargs.mk @@ -0,0 +1,31 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_Executable_Executable,processcmdlineargs)) + +$(eval $(call gb_Executable_set_include,processcmdlineargs,\ + $$(INCLUDE) \ + -I$(SRCDIR)/sal/inc \ +)) + +$(eval $(call gb_Library_add_defs,processcmdlineargs,\ + -DSAL_DLLIMPLEMENTATION \ +)) + +$(eval $(call gb_Executable_use_libraries,processcmdlineargs,\ + sal \ +)) + +$(eval $(call gb_Executable_add_exception_objects,processcmdlineargs,\ + sal/workben/osl/processcmdlineargs \ +)) + +$(call gb_Executable_get_clean_target,processcmdlineargs) : + rm -f $(WORKDIR)/LinkTarget/Executable/processcmdlineargs +# vim: set ts=4 sw=4 et: diff --git a/sal/Module_sal.mk b/sal/Module_sal.mk index 6b8e261dee4d..95f88ffbd1ef 100644 --- a/sal/Module_sal.mk +++ b/sal/Module_sal.mk @@ -27,6 +27,7 @@ $(eval $(call gb_Module_add_targets,sal,\ Executable_config \ Executable_processworkdir \ Executable_getprocessinfo \ + Executable_processcmdlineargs \ )) $(eval $(call gb_Module_add_check_targets,sal,\ diff --git a/sal/workben/osl/processcmdlineargs.cxx b/sal/workben/osl/processcmdlineargs.cxx new file mode 100644 index 000000000000..a87bf8345a16 --- /dev/null +++ b/sal/workben/osl/processcmdlineargs.cxx @@ -0,0 +1,75 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/main.h> +#include <sal/log.hxx> +#include <rtl/ustring.h> +#include <rtl/alloc.h> +#include <osl/thread.h> + +#include <osl/process.h> + +#include <cstdio> + +SAL_IMPLEMENT_MAIN() +{ + rtl_uString *pustrExePath = nullptr; + rtl_String *pstrExePath = nullptr; + + fprintf(stdout, "List process arguments\n"); + + osl_getExecutableFile(&pustrExePath); + rtl_uString2String(&pstrExePath, + rtl_uString_getStr(pustrExePath), + rtl_uString_getLength(pustrExePath), + osl_getThreadTextEncoding(), + OUSTRING_TO_OSTRING_CVTFLAGS); + rtl_freeMemory(pustrExePath); + + fprintf(stdout, " Process executable image: %s\n", rtl_string_getStr(pstrExePath)); + rtl_freeMemory(pstrExePath); + + sal_uInt32 argc = osl_getCommandArgCount(); + + if (argc > 0) + { + for (sal_uInt32 i = 0; i < argc; i++) + { + rtl_uString *pustrArgument = nullptr; + rtl_String *pstrArgument = nullptr; + + osl_getCommandArg(i, &pustrArgument); + rtl_uString2String(&pstrArgument, + rtl_uString_getStr(pustrArgument), + rtl_uString_getLength(pustrArgument), + osl_getThreadTextEncoding(), + OUSTRING_TO_OSTRING_CVTFLAGS); + + rtl_freeMemory(pustrArgument); + + fprintf(stdout, " Process argument %d: %s\n", i, rtl_string_getStr(pstrArgument)); + + rtl_freeMemory(pstrArgument); + } + } + + return 0; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits