Hi all,
On Wed, 16 Jan 2008, Ian Tickle wrote:
> I'm rather surprised that is the complete explanation, for the simple
> reason that Perl (or any program for that matter) already inherits all
> the environment variables from the shell in which it is run, including
> PATH, CINCL, CLIBD_MON etc which would be needed to run pdbset, refmac
> etc. In fact sourcing ccp4.setup from within Perl in the way suggested
> will be very inefficient if you have several system calls since you
> would have to do it in *every* system call that runs a CCP4 program,
> i.e. the variable settings are not saved from one system call to the
> next.
I don't believe that just doing
system("source ccp4.setup");
in a Perl script will have any effect: if you check the return status of the
above "system" function call you will find that it returns an error status. As
described in the Perl documentation for "system", you can do this easily as
follows:
system("source env.test") == 0 or die "system call failed: $?";
This is because when "system" has only one argument, and that argument
contains no shell metacharacters, that argument is split into words and passed
to the system call execvp (do "man execvp" for details). execvp requires a
executable file to run (either a binary, or a script of some type), and
"source" is not an executable file. It is a builtin command of the shells csh,
tcsh and bash. There is no executable file or script in /usr/bin or anywhere
else on your $PATH in a standard Unix-family OS (unless you have put one there
yourself).
You could force "system" to execute in a shell instead of using execvp by
including a metacharacter in the argument like this:
system("source ccp4.setup;");
or use an explicit shell invocation:
system("/bin/bash -c 'source ccp4.setup'");
As long as ccp4.setup contains no errors, this function will return a
successful status, but even that will have no effect on your script. The
"system" function forks a child process to execute its argument. Your script
will then wait for the child process to terminate before continuing. Modifying
the environment of a child process will not have any effect on the environment
of its parent. You could do something like:
system("source ccp4.setup; pdbset ...");
as Ed suggested, although see below for a portability issue. As Ian points out
this can get inefficient, and shouldn't be necessary anyway (unless you want
to use different versions of CCP4 at different places in your script).
> As Ed pointed out you didn't say what the *exact* error message was when
> you tried it the first time (which is always a good idea when reporting
> a problem!). You said that the CCP4 programs work normally from the
> command line which implies that the environment is correctly set up, so
> the only conclusion I can come to is that you didn't source ccp4.setup
> in the shell that you were running Perl in. I always do exactly that
I think that Ian is correct here: whether your script works depends on whether
CCP4 has been set up in the shell where you run your script.
> (in my .login startup script so it's only run once when I login - I use
> tcsh), then just as a check in all my Perl scripts the first line is
> always:
>
> if(!defined($ENV{"CCP4"})){
> die("You must set up the CCP4 environment.\n");
> }
>
> Also note that your solution won't work anyway if the user's default
> shell is csh or tcsh because the system call in Perl uses sh by default,
> whereas ccp4.setup will normally have been configured to be compatible
> with csh or tcsh.
Not only this, but standard /bin/sh doesn't have a "source" command. It works
on many Linux distributions because /bin/sh is a link to bash, or otherwise
has some bash functionality. For portability, you should use the standard
Bourne-shell "." command:
system(". ccp4.setup; pdbset ....");
Hope that this makes things clearer,
Peter.
>
> HTH
>
> -- Ian
>
>> -----Original Message-----
>> From: [log in to unmask]
>> [mailto:[log in to unmask]] On Behalf Of
>> [log in to unmask]
>> Sent: 15 January 2008 20:37
>> To: Ed Hoeffner
>> Cc: [log in to unmask]
>> Subject: Re: Perl
>>
>> Hi,
>>
>> thanks for all the help!
>>
>> system ("source ccp4.setup")
>>
>> does the trick, every time before a ccp4 script is called,
>> the environmental
>> parameters have to be set up this way.
>>
>>
>> Quoting Ed Hoeffner <[log in to unmask]>:
>>
>>> Hi
>>>
>>> You don't include any error messages, so it's very difficult to
>>> troubleshoot.
>>>
>>> However, as a wild guess, I'd suggest you ensure that you
>> execute the ccp4
>>> setup file and then try your command. I don't know perl,
>> but the call might
>>> look something like system("source ccp4.setup ; pdbset
>> ..."). As I recall,
>>> there is a ccp4 setup file that has to be loaded first,
>> though you may have
>>> to find it and adjust that part of the command accordingly
>> so the file can
>>> be located.
>>>
>>> Ed
>>>
>>>
>>
>>
>> --
>>
>>
>
>
> Disclaimer
> This communication is confidential and may contain privileged information intended solely for the named addressee(s). It may not be used or disclosed except for the purpose for which it has been sent. If you are not the intended recipient you must not review, use, disclose, copy, distribute or take any action in reliance upon it. If you have received this communication in error, please notify Astex Therapeutics Ltd by emailing [log in to unmask] and destroy all copies of the message and any attached documents.
> Astex Therapeutics Ltd monitors, controls and protects all its messaging traffic in compliance with its corporate email policy. The Company accepts no liability or responsibility for any onward transmission or use of emails and attachments having left the Astex Therapeutics domain. Unless expressly stated, opinions in this message are those of the individual sender and not of Astex Therapeutics Ltd. The recipient should check this email and any attachments for the presence of computer viruses. Astex Therapeutics Ltd accepts no liability for damage caused by any virus transmitted by this email. E-mail is susceptible to data corruption, interception, unauthorized amendment, and tampering, Astex Therapeutics Ltd only send and receive e-mails on the basis that the Company is not liable for any such alteration or any consequences thereof.
> Astex Therapeutics Ltd., Registered in England at 436 Cambridge Science Park, Cambridge CB4 0QA under number 3751674
>
|