#include <stdio.h>
#include <string.h>
#include <malloc.h>
#define  MORESPACE  32

extern int is_nt(void);
extern FILE *win32_popen(char *a, char *b);

FILE *k_popen(char *cmd, char *mode)
{
  FILE *ret;
  char *tmpcmd = (char *)malloc(strlen(cmd) + MORESPACE);
  if(is_nt()) {
    (void)strcpy(tmpcmd, "cmd /c ");
  } else {
    char *p;
    p = (char *)getenv("COMSPEC");
    if(p) {
      strcpy(tmpcmd, p);
      strcat(tmpcmd, " /c ");
      free(p);
    } else {
      strcpy(tmpcmd, "command /c ");
    }
  }
  (void)strcat(tmpcmd, cmd);
  ret = win32_popen(tmpcmd, mode);
  free(tmpcmd);
  return ret;
}
