GNU Octave
4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
async-system-wrapper.c
Go to the documentation of this file.
1
/*
2
3
Copyright (C) 2016-2018 John W. Eaton
4
5
This file is part of Octave.
6
7
Octave is free software: you can redistribute it and/or modify it
8
under the terms of the GNU General Public License as published by
9
the Free Software Foundation, either version 3 of the License, or
10
(at your option) any later version.
11
12
Octave is distributed in the hope that it will be useful, but
13
WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
16
17
You should have received a copy of the GNU General Public License
18
along with Octave; see the file COPYING. If not, see
19
<https://www.gnu.org/licenses/>.
20
21
*/
22
23
// areadlink is provided by gnulib. We don't include gnulib headers
24
// directly in Octave's C++ source files to avoid problems that may be
25
// caused by the way that gnulib overrides standard library functions.
26
27
#if defined (HAVE_CONFIG_H)
28
# include "config.h"
29
#endif
30
31
#if defined (__WIN32__) && ! defined (__CYGWIN__)
32
# include <stdlib.h>
33
# include <string.h>
34
# define WIN32_LEAN_AND_MEAN 1
35
# include <windows.h>
36
#else
37
# include <sys/types.h>
38
# include <unistd.h>
39
#endif
40
41
#include "
async-system-wrapper.h
"
42
43
pid_t
44
octave_async_system_wrapper
(
const
char
*cmd)
45
{
46
int
retval
= -1;
47
48
if
(! cmd)
49
return
retval
;
50
51
#if defined (OCTAVE_USE_WINDOWS_API)
52
53
STARTUPINFO si;
54
PROCESS_INFORMATION
pi
;
55
56
ZeroMemory (&si,
sizeof
(si));
57
ZeroMemory (&
pi
,
sizeof
(
pi
));
58
59
char
*xcmd = (
char
*) malloc (
strlen
(cmd) + 1);
60
61
strcpy (xcmd, cmd);
62
63
if
(! CreateProcess (0, xcmd, 0, 0, FALSE, 0, 0, 0, &si, &
pi
))
64
retval
= -1;
65
else
66
{
67
retval
=
pi
.dwProcessId;
68
69
CloseHandle (
pi
.hProcess);
70
CloseHandle (
pi
.hThread);
71
}
72
73
free (xcmd);
74
75
#else
76
77
pid_t pid =
fork
();
78
79
if
(pid == 0)
80
execl (
SHELL_PATH
,
"sh"
,
"-c"
, cmd, (
char
*) (0));
81
else
82
retval
= pid;
83
84
#endif
85
86
return
retval
;
87
}
SHELL_PATH
#define SHELL_PATH
Definition:
oct-procbuf.cc:56
octave_async_system_wrapper
pid_t octave_async_system_wrapper(const char *cmd)
Definition:
async-system-wrapper.c:44
retval
octave_value retval
Definition:
data.cc:6246
strlen
T::size_type strlen(const typename T::value_type *str)
Definition:
oct-string.cc:75
async-system-wrapper.h
octave::sys::fork
pid_t fork(std::string &msg)
Definition:
oct-syscalls.cc:97
octave::math::pi
static const double pi
Definition:
lo-specfun.cc:1996
liboctave
wrappers
async-system-wrapper.c
Generated on Sat Sep 1 2018 14:01:47 for GNU Octave by
1.8.14