BookmarkSubscribeRSS Feed
jmspy
Fluorite | Level 6

Hello-

 

I have a bash shell script that works perfectly fine when executing it from the UNIX command line, however when trying to execute it from SAS it ignore the redirects.

Here's the shell script:

#!/bin/bash

while IFS="" read -r idnumber|| [ -n "$idnumber" ]
do
curl -k -s -H 'placeholderheader' | \
/env/python -c "import sys, json; print('"$idnumber",' + str(json.load(sys.stdin)['Clients'][0]['ClientId']))" \
>> idfile.txt
done < sourcefile.txt

Executing this in terminal produces an output to that text file without issue, but that does not happen when executing from SAS:

	data _null_;
		call system('/mydirectory/python/ClientID/clientcurl.sh');
	run;

Runs without SAS error, but nothing is appended to the text file.  I understand that the "instance" that SAS creates to execute this system command is different to how one uses terminal, but does anyone know if there is a way to get around this issue?

 

Thanks!

 

7 REPLIES 7
Kurt_Bremser
Super User

You did not specify the absolute path names to idfile.txt and sourcefile.txt.

Your SAS process has a different current working directory, so you need the absolute path.

jmspy
Fluorite | Level 6
I apologize, I do have the absolute paths in there I just trimmed it for security's sake 🙂
Kurt_Bremser
Super User

Run the external command with a pipe:

filename oscmd pipe '/mydirectory/python/ClientID/clientcurl.sh 2>&1';

data _null_;
infile oscmd;
input;
put _infile_;
run;

and see if the SAS log reveals anything.

jmspy
Fluorite | Level 6

I attempted the method you posted, and I receive this error in the output:

raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

My assumption is that the way I am redirecting the source file could be the culprit, especially since it works perfectly in terminal:

done < /mydirectory/sourcefile.txt

The instance that runs this script seems to not be able to reference that source file, but I don't know enough about how SAS executes system tasks like this.

Tom
Super User Tom
Super User

See if your SAS session can read the file.  Try reading the first 10 lines.

data _null_;
  infile '/mydirectory/sourcefile.txt' obs=10;
  input;
  list;
run;
smantha
Lapis Lazuli | Level 10

Does sas user have permissions to run system calls? Then there is the absolute path thing that @Kurt_Bremser pointed out.

jmspy
Fluorite | Level 6
Yes I can execute scripts that run smb client and native python scripts (where I don't redirect outputs)

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 970 views
  • 1 like
  • 4 in conversation