Andre Steenveld wrote:
> I try to convert some source code from unix to windows. It uses a sequence
> of calls to fork()... execute()... waitpid(). And I can't find anything the
> same in windows but I found CreateProcess(). So I try to work around the
> fork() problem but I can't get CreateProcess() to work.
I don't understand the nuances of fork() etc.,
but I think you just want to exec a process and
wait for it to finish. Here's code I use in
production for that purpose. Sample call:
assert(0 == run_program("md5sum --check --status validated.md5"));
// Wrapper for win32 CreateProcess().
// Copyright (C) 2001, 2002, 2003 Gregory W. Chicares.
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// email (preferred) <chicares@...>
// snail: Chicares, 186 Belle Woods Dr., Glastonbury CT 06033, USA
inline int run_program
(std::string const& a_cmd_line
,std::string const& a_path = ""
std::memset(&startup_info, 0, sizeof(STARTUPINFO));
startup_info.cb = sizeof(STARTUPINFO);
char* non_const_cmd_line_copy = new char[1 + a_cmd_line.size()];
char const* path = ("" == a_path) ? 0 : a_path.c_str();
#endif // create_process_hpp