31 #include <sys/types.h>
36 #if defined (__WIN32__) && ! defined (__CYGWIN__)
37 #define WIN32_LEAN_AND_MEAN
57 char *tmp = gnulib::getcwd (0, 0);
75 #if defined (__WIN32__) && ! defined (__CYGWIN__)
76 if (path.length () == 2 && path[1] ==
':')
80 return gnulib::chdir (path.c_str ());
83 #if defined (__WIN32__) && ! defined (__CYGWIN__)
86 octave_popen2 (
const std::string& cmd,
const string_vector& args,
88 int *fildes, std::string& msg)
91 PROCESS_INFORMATION pi;
93 std::string command =
"\"" + cmd +
"\"";
94 HANDLE hProcess = GetCurrentProcess ();
95 HANDLE childRead, childWrite, parentRead, parentWrite;
98 ZeroMemory (&pi,
sizeof (pi));
99 ZeroMemory (&si,
sizeof (si));
102 if (! CreatePipe (&childRead, &parentWrite, 0, 0)
103 || ! DuplicateHandle (hProcess, childRead, hProcess, &childRead,
105 DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE))
107 msg =
"popen2: pipe creation failed";
110 if (! CreatePipe (&parentRead, &childWrite, 0, 0)
111 || ! DuplicateHandle (hProcess, childWrite, hProcess, &childWrite,
113 DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE))
115 msg =
"popen2: pipe creation failed";
120 pipeMode = PIPE_NOWAIT;
121 SetNamedPipeHandleState (parentRead, &pipeMode, 0, 0);
123 fildes[1] = _open_osfhandle (reinterpret_cast<intptr_t> (parentRead),
124 _O_RDONLY | _O_BINARY);
125 fildes[0] = _open_osfhandle (reinterpret_cast<intptr_t> (parentWrite),
126 _O_WRONLY | _O_BINARY);
127 si.dwFlags |= STARTF_USESTDHANDLES;
128 si.hStdInput = childRead;
129 si.hStdOutput = childWrite;
132 for (
int k=1; k<args.
length (); k++)
133 command +=
" \"" + args[k] +
"\"";
135 strcpy (c_command, command.c_str ());
136 if (! CreateProcess (0, c_command, 0, 0, TRUE, 0, 0, 0, &si, &pi))
138 msg =
"popen2: process creation failed";
141 pid = pi.dwProcessId;
143 CloseHandle (childRead);
144 CloseHandle (childWrite);
145 CloseHandle (pi.hProcess);
146 CloseHandle (pi.hThread);
int octave_chdir(const std::string &path_arg)
static std::string tilde_expand(const std::string &)
liboctave_error_handler current_liboctave_error_handler
octave_idx_type length(void) const
Number of elements in the array.
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
std::string octave_getcwd(void)