On 12/16/2015 4:32 PM, Jens Alfke wrote:
On Dec 16, 2015, at 3:23 PM, pscott <psc...@skycoast.us <mailto: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.)

I use tcsh. Not for scripting — that would be sick— just as my login shell. I got used to it and find its history and line editing the sanest. Personal preference, obviously.

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.

Are you sure about that? Every linux or bsd system I ever ran into says in the system(3) man page that /bin/sh is used, and that's a pretty stable shell across systems, at least for the basic sh functionality. It may be a POSIX thing. Now, the SHELL environment variable can't be trusted in that case, because system() just propagates the environment, but if your executed program is a /bin/sh script it will execute fine without a shebang line regardless of what shell your c program was run from or what SHELL indicates.

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 [...]

I'll concede that system() might not be the best approach for some uses/applications. But it wasn't me who suggested it, either. I only pointed out that the commas and export weren't needed.

Paul

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

_______________________________________________

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