Verified Commit 464f7de9 authored by Camil Staps's avatar Camil Staps 🐨

Add function RunExternalCommand to MacOSX version of PmCleanSystem

parent d055533f
......@@ -92,3 +92,5 @@ ClearCompilerCaches :: .a
SendRepeatResult :: .a
StartCodeGenerator :: .a
Execute` :: .a
RunExternalCommand :: !String ![String] !String !*GeneralSt -> *(!Int, ![String], !*GeneralSt)
......@@ -981,6 +981,61 @@ StartCodeGenerator = abort "StartCodeGenerator\n"
Execute` :: .a
Execute` = abort "Execute`\n"
RunExternalCommand :: !String ![String] !String !*GeneralSt -> *(!Int, ![String], !*GeneralSt)
RunExternalCommand cmd args startupdir ps
# temp_dir = temp_dir_path startupdir
errors_file_name = errors_file_path temp_dir 0
# stderr_fd = creat (errors_file_name+++"\0") 0644
| stderr_fd== (-1)
= abort "creat failed\n"
# (argv,args_memory) = make_argv [cmd : args]
# pid = fork
| pid<0
= abort "fork failed\n"
| pid==0
# r=dup2 stderr_fd 2
| r== (-1)
= abort "dup2 failed\n"
| execv (cmd+++"\0") argv<0
= abort "execv failed\n"
= abort "execution continued after execv\n"
| free args_memory<0
= abort "free failed\n"
# (w_pid,status) = wait_pid pid 0
| w_pid <> -1 && w_pid<>pid
= abort "waitpid failed\n"
# result = (status bitand 0xff00) >> 8
# wtermsig = status bitand 0x7f
| wtermsig<>0
= abort "external command exited abnormally\n"
# r=close stderr_fd
| r==(-1)
= abort "close failed\n"
# (out,ps) = accFiles (readFileLines errors_file_name) ps
= (result,out,ps)
where
readFileLines :: !String !*Files -> *(![String], !*Files)
readFileLines path env
# (ok,f,env) = fopen path FReadText env
| not ok = ([], env)
# (out,f) = read [] f
# (_,env) = fclose f env
= (out,env)
where
read :: ![String] !*File -> *(![String], !*File)
read acc f
# (e,f) = fend f
| e = (reverse acc,f)
# (line,f) = freadline f
#! line = strip_newlines line
= read [line:acc] f
wait_pid :: !Int !Int -> (!Int,!Int)
wait_pid pid options
# status_a = createArray 1 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment