diff --git a/contrib/process/load.factor b/contrib/process/load.factor new file mode 100644 index 0000000000..0610e62f28 --- /dev/null +++ b/contrib/process/load.factor @@ -0,0 +1,7 @@ +IN: process +USING: kernel ; +PROVIDE: contrib/process { + { "os-unix.factor" [ unix? ] } + { "os-windows.factor" [ windows? ] } + "process.factor" +} ; diff --git a/contrib/process/os-unix.factor b/contrib/process/os-unix.factor new file mode 100644 index 0000000000..dd1d74298e --- /dev/null +++ b/contrib/process/os-unix.factor @@ -0,0 +1,11 @@ +IN: process +USING: compiler io io-internals kernel parser generic ; + +LIBRARY: libc +FUNCTION: int system ( char* command ) ; +FUNCTION: void* popen ( char* command, char* type ) ; +FUNCTION: int pclose ( void* file ) ; + +: run-process ( string -- ) system io-error ; +: run-detached ( string -- ) " &" append run-process ; + diff --git a/contrib/process/os-windows.factor b/contrib/process/os-windows.factor new file mode 100644 index 0000000000..c856662f95 --- /dev/null +++ b/contrib/process/os-windows.factor @@ -0,0 +1,15 @@ +IN: process +USING: alien compiler io io-internals kernel math parser generic win32-api ; + +: (run-process) ( string flag -- ) + >r f swap + f f 0 r> f f + "STARTUPINFO" "STARTUPINFO" c-size over set-STARTUPINFO-cb + "PROCESS_INFORMATION" CreateProcess zero? [ win32-error ] when ; + +: run-process + 0 (run-process) ; + +: run-detached ( string -- ) + DETACH_PROCESS (run-process) ; + diff --git a/contrib/process.factor b/contrib/process/process.factor similarity index 68% rename from contrib/process.factor rename to contrib/process/process.factor index b4c1f6779b..c5e0bc95e6 100644 --- a/contrib/process.factor +++ b/contrib/process/process.factor @@ -1,12 +1,6 @@ IN: process USING: compiler io io-internals kernel parser generic ; -LIBRARY: libc -FUNCTION: int system ( char* command ) ; - -FUNCTION: void* popen ( char* command, char* type ) ; -FUNCTION: int pclose ( void* file ) ; - TUPLE: process-stream pipe ; C: process-stream ( command mode -- stream ) @@ -20,4 +14,3 @@ M: process-stream stream-close : !" parse-string system drop ; parsing -PROVIDE: contrib/process ;