> On Dec 16, 2015, at 3:23 PM, pscott <psc...@skycoast.us> wrote:
> 
> I am pretty sure you can do that as one command without semicolons or export. 
> I.e,
> 
> system("PYTHONPATH=/usr/bin/python PYTHONHOME=/usr/share/python/ 
> /path/to/script args");

Not all shells support that syntax. I know that tcsh didn’t (I used it for 
years.)

system() is a terrible function to use in production code, for several reasons. 
One, it can invoke different shells for different users, so you can’t be sure 
about exactly what shell features it will support. Two, you have to glom all 
the args into one string, so you need to be VERY VERY CAREFUL about quoting and 
escaping meta-characters like quotes and backslashes in any strings that you 
substitute into the command line, or EXTREMELY BAD* things can happen. (And 
remember, you can’t be sure about exactly what the shell’s rules are for 
quoting and escaping, because _you don’t know what shell it is_. Are 
backslashes escaped inside a single-quoted string? I don’t know; they are in 
bash and zsh, but they might not be in tcsh or fish or COMMAND.COM.)

It would be much better to use popen instead. Or at least fork+execve.

—Jens

* Apple released an updater for iTunes, circa 2001, that had a bug of this 
nature. It ended up deleting several people’s home directories; IIRC because 
the path to their home directory contained a space.
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to