Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Add :directory parameter to ccl:run-program #337

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion doc/manual/external-process.ccldoc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
this.")))
(defsection "External-Program Dictionary"
(definition (:function run-program)
"run-program program args &key (wait t) pty sharing input if-input-does-not-exist output (if-output-exists :error) (error :output) (if-error-exists :error) status-hook external-format env (silently-ignore-catastrophic-failures *silently-ignore-catastrophic-failure-in-run-program*)"
"run-program program args &key (wait t) pty sharing input if-input-does-not-exist output (if-output-exists :error) (error :output) (if-error-exists :error) status-hook external-format env directory (silently-ignore-catastrophic-failures *silently-ignore-catastrophic-failure-in-run-program*)"
"Invokes an external program as an OS subprocess
of lisp."
(defsection "Arguments and Values"
Expand Down Expand Up @@ -109,6 +109,10 @@
value are case sensitive strings. See "
(ref (definition :function setenv)) ".
")
(item "{param directory}" ccldoc::=> "
A string or pathname denoting directory that will
become the working directory of the external
process.")
(item "{param silently-ignore-catastrophic-failures}" ccldoc::=> "
If NIL, signal an error if run-program is unable
to start the program. If non-NIL, treat failure to
Expand Down
7 changes: 5 additions & 2 deletions level-1/linux-files.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,7 @@ any EXTERNAL-ENTRY-POINTs known to be defined by it to become unresolved."
(remove-external-process p)
(setq terminated t)))))))))))

(defun run-external-process (proc in-fd out-fd error-fd argv &optional env)
(defun run-external-process (proc in-fd out-fd error-fd argv &optional env dir)
(let* ((signaled nil))
(unwind-protect
(let ((child-pid (#_fork)))
Expand All @@ -1423,6 +1423,8 @@ any EXTERNAL-ENTRY-POINTs known to be defined by it to become unresolved."
(setq signaled t)
(dolist (pair env)
(setenv (string (car pair)) (cdr pair)))
(when dir
(%chdir (defaulted-native-namestring dir)))
(without-interrupts
(exec-with-io-redirection
in-fd out-fd error-fd argv)))
Expand Down Expand Up @@ -1456,6 +1458,7 @@ itself, by setting the status and exit-code fields.")
(error :output) (if-error-exists :error)
status-hook (element-type 'character)
env
directory
(sharing :private)
(external-format `(:character-encoding ,*terminal-character-encoding-name*))
(silently-ignore-catastrophic-failures
Expand Down Expand Up @@ -1526,7 +1529,7 @@ itself, by setting the status and exit-code fields.")
external-format)))
(with-string-vector (argv args encoding)
(run-external-process proc in-fd out-fd error-fd argv
env)))))
env directory)))))
(wait-on-semaphore (external-process-signal proc)))
(dolist (fd close-in-parent) (fd-close fd))
(unless (external-process-pid proc)
Expand Down