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