Advertisement
Guest User

evaluate_command(prog, arg)

a guest
Jan 10th, 2022
854
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // implementation
  2. function evaluate_command(prog, arg) {
  3.   prog = string_replace_all(prog, @'\', @'\\');
  4.  prog = string_replace_all(prog, @'"', @'\"');
  5.  if (os_type == os_windows &&
  6.    (string_lower(filename_name(prog)) == "cmd" ||
  7.    string_lower(filename_name(prog)) == "cmd.exe"))
  8.  { prog = "cmd.exe"; arg = "/c " + arg; }
  9.  prog = @'"' + prog + @'"'; var pre = "";
  10.  if (os_type == os_windows) pre = "cmd /c";
  11.  var pid = ProcessExecute(pre + " " +prog + " " + arg);
  12.  var out = ExecutedProcessReadFromStandardOutput(pid);
  13.  FreeExecutedProcessStandardInput(pid);
  14.  FreeExecutedProcessStandardOutput(pid);
  15.  return out;
  16. }
  17.  
  18. // usage example
  19. show_message(evaluate_command("echo", "Hello World!"));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement