[plt-scheme] process.ss can't find command
On Mar 12, Stephen De Gabrielle wrote:
> Thanks,
>
> I don't need the path, so I modified your suggestion;
>
> (system "/bin/sh -c \". /etc/profile;. ~/.profile ;svn commit -m
> \"auto-commit\"\"")
This approach is *extremely* fragile, and likely to break in all kinds
of ways. One thing that is already broken are your quotes, it should be
(system "/bin/sh -c \". /etc/profile;. ~/.profile ;svn commit -m
\\\"auto-commit\\\"\"")
But it's a bad idea in way you look at it. If all you need is the
PATH, then I recommend writing code *just* for OSX to set *just* the
PATH. Here's a sketch that seems reasonable:
(when (equal? 'macosx (system-type))
(parameterize ([current-output-port (open-output-string)])
(if (system* "/bin/sh" "-c"
". /etc/profile ; printf \"%s\" \"$PATH\"")
(putenv "PATH" (get-output-string (current-output-port)))
(error "something bad happened"))))
Once you have that, I recommend using `system*' to invoke executables,
so you don't end up in shell-quoting-hell. I usually like to make a
scheme function that behaves like the command, something like this:
(define svn
(let ([exe (or (find-executable-path "svn")
(error 'svn "cannot find executable"))])
(lambda args
(apply system* exe args))))
And then
(svn "commit" "-m" "auto-commit")
(Warning: I didn't test any of the above code, but it should get you
closer to a better solution.)
> Works nicely. (I'm this will work on my linux machine)
>
> Weirdly a 'read'-syle[eof] prompt appears then disappears - without
> need for input.
If you're running this from DrScheme, then when the process starts it
gets all input -- drscheme gives you a chance to feed the process that
input, because it cannot tell that the process will never use it. To
avoid that, make sure that the subprocess is always working from an
explicitly empty input, for example:
(parameterize ([current-input-port (open-input-string "")])
...your-code...)
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://www.barzilay.org/ Maze is Life!