shell() problems

I need to run a couple of shell commands on the machine that serves up our tests, to get the updated scripts from source control:

put "p4 sync -f" into theCommand
put shell(theCommand) into someStuff
put the result into error
if error is not 0
  put "Error Code:"&&error  
  put someStuff
end if

my output:

Error Code: 1
someStuff
(empty)

The exact same command (cut and pasted) into Terminal works just fine. I’m surprised that I don’t get an error back from the p4 command, it’s pretty verbose in telling me when something didn’t work. It shows up in the console, telling me that the host is unknown, which suggests that it is not picking up ENV from the system.

Is there a way to get shell() to pick up the ENV? I can set up a config file and pipe in the credentials, but I’ve already got the system set up, so I’m hoping to avoid that.

Thanks for any help!

Allen

We did figure out how to get around this. We had to create a separate shell script that loads all of the environment variables we wanted to use and then do the commands.

#!/bin/sh
export VAR1=myvalue
export VAR2=myothervalue
p4 login
p4 -c "MyWorkspace" sync -f
p4 logout.

Why doesn’t Eggplant use the user’s predefined environment?

If you use the open process command instead of shell() you’ll have the option to pass a set of environment variables:

open process "/bin/sh" with options (environment:(VAR1:myvalue, VAR2:myothervalue))
write "echo $VAR1" return to process "/bin/sh"
read from process "/bin/sh" until end
put it -- shows 'myvalue'
close process "/bin/sh"

If you want to include all of the current environment variables, you can get them using the env() function, and add or replace other properties:

set shellEnv to env() replacing properties (VAR1:myvalue, VAR2:myothervalue)
open process "/bin/sh" with options (environment:shellEnv)
...

I think that will give you what you want.

I will try that. Thanks!

Just curious as to why I have to do that. Shouldn’t env() and ENV produce the same thing? :?:

Thanks again for all your help! Happy Holidays/Vacation Days :wink:

When you use “open process” without specifying a set of environment variables, the process inherits the environment from Eggplant, so it will have the same environment variable values as given by the env() function.

If you provide a set of environment variable values, though, the values you provide are taken as the full set of initial values. So if you want to pass along values from env() you have to do it explicitly.

Does that answer your question? Or did I misconstrue the question? :wink: