From d4f682c7bd1ca150693fa3028d0a8c6bdd1820fd Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Fri, 28 Oct 2011 12:50:30 -0500 Subject: FbCommands.cc: Implement ExecuteCmd for Windows --- src/FbCommands.cc | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/FbCommands.cc b/src/FbCommands.cc index be52e47..63aa79d 100644 --- a/src/FbCommands.cc +++ b/src/FbCommands.cc @@ -113,15 +113,26 @@ ExecuteCmd::ExecuteCmd(const string &cmd, int screen_num):m_cmd(cmd), m_screen_n } void ExecuteCmd::execute() { -#ifndef __EMX__ run(); -#else // __EMX__ - spawnlp(P_NOWAIT, "cmd.exe", "cmd.exe", "/c", m_cmd.c_str(), static_cast(NULL)); -#endif // !__EMX__ - } int ExecuteCmd::run() { +#if defined(__EMX__) || defined(_WIN32) +#ifndef PATH_MAX +#define PATH_MAX 1024 +#endif + char comspec[PATH_MAX] = {0}; + char * env_var = getenv("COMSPEC"); + if (env_var != NULL) { + strncpy(comspec, env_var, PATH_MAX - 1); + comspec[PATH_MAX - 1] = '\0'; + } else { + strncpy(comspec, "cmd.exe", 7); + comspec[7] = '\0'; + } + + return spawnlp(P_NOWAIT, comspec, comspec, "/c", m_cmd.c_str(), static_cast(NULL)); +#else pid_t pid = fork(); if (pid) return pid; @@ -161,6 +172,7 @@ int ExecuteCmd::run() { exit(EXIT_SUCCESS); return pid; // compiler happy -> we are happy ;) +#endif } FbTk::Command *ExportCmd::parse(const string &command, const string &args, -- cgit v0.11.2