<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Call System to run a python program with a redirect to a text file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Call-System-to-run-a-python-program-with-a-redirect-to-a-text/m-p/664747#M198644</link>
    <description>&lt;P&gt;You did not specify the absolute path names to idfile.txt and sourcefile.txt.&lt;/P&gt;
&lt;P&gt;Your SAS process has a different current working directory, so you need the absolute path.&lt;/P&gt;</description>
    <pubDate>Wed, 24 Jun 2020 19:08:36 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-06-24T19:08:36Z</dc:date>
    <item>
      <title>Call System to run a python program with a redirect to a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Call-System-to-run-a-python-program-with-a-redirect-to-a-text/m-p/664740#M198638</link>
      <description>&lt;P&gt;Hello-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Here's the shell script:&lt;/P&gt;&lt;PRE&gt;#!/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']))" \
&amp;gt;&amp;gt; idfile.txt
done &amp;lt; sourcefile.txt&lt;/PRE&gt;&lt;P&gt;Executing this in terminal produces an output to that text file without issue, but that does not happen when executing from SAS:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	data _null_;
		call system('/mydirectory/python/ClientID/clientcurl.sh');
	run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Runs without SAS error, but nothing is appended to the text file.&amp;nbsp; 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?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jun 2020 18:59:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Call-System-to-run-a-python-program-with-a-redirect-to-a-text/m-p/664740#M198638</guid>
      <dc:creator>jmspy</dc:creator>
      <dc:date>2020-06-24T18:59:29Z</dc:date>
    </item>
    <item>
      <title>Re: Call System to run a python program with a redirect to a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Call-System-to-run-a-python-program-with-a-redirect-to-a-text/m-p/664747#M198644</link>
      <description>&lt;P&gt;You did not specify the absolute path names to idfile.txt and sourcefile.txt.&lt;/P&gt;
&lt;P&gt;Your SAS process has a different current working directory, so you need the absolute path.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jun 2020 19:08:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Call-System-to-run-a-python-program-with-a-redirect-to-a-text/m-p/664747#M198644</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-06-24T19:08:36Z</dc:date>
    </item>
    <item>
      <title>Re: Call System to run a python program with a redirect to a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Call-System-to-run-a-python-program-with-a-redirect-to-a-text/m-p/664755#M198649</link>
      <description>I apologize, I do have the absolute paths in there I just trimmed it for security's sake &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Wed, 24 Jun 2020 19:23:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Call-System-to-run-a-python-program-with-a-redirect-to-a-text/m-p/664755#M198649</guid>
      <dc:creator>jmspy</dc:creator>
      <dc:date>2020-06-24T19:23:09Z</dc:date>
    </item>
    <item>
      <title>Re: Call System to run a python program with a redirect to a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Call-System-to-run-a-python-program-with-a-redirect-to-a-text/m-p/664757#M198651</link>
      <description>&lt;P&gt;Run the external command with a pipe:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename oscmd pipe '/mydirectory/python/ClientID/clientcurl.sh 2&amp;gt;&amp;amp;1';

data _null_;
infile oscmd;
input;
put _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and see if the SAS log reveals anything.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jun 2020 19:32:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Call-System-to-run-a-python-program-with-a-redirect-to-a-text/m-p/664757#M198651</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-06-24T19:32:32Z</dc:date>
    </item>
    <item>
      <title>Re: Call System to run a python program with a redirect to a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Call-System-to-run-a-python-program-with-a-redirect-to-a-text/m-p/664758#M198652</link>
      <description>&lt;P&gt;Does sas user have permissions to run system calls? Then there is the absolute path thing that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;pointed out.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jun 2020 19:35:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Call-System-to-run-a-python-program-with-a-redirect-to-a-text/m-p/664758#M198652</guid>
      <dc:creator>smantha</dc:creator>
      <dc:date>2020-06-24T19:35:50Z</dc:date>
    </item>
    <item>
      <title>Re: Call System to run a python program with a redirect to a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Call-System-to-run-a-python-program-with-a-redirect-to-a-text/m-p/664789#M198660</link>
      <description>Yes I can execute scripts that run smb client and native python scripts (where I don't redirect outputs)</description>
      <pubDate>Wed, 24 Jun 2020 21:20:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Call-System-to-run-a-python-program-with-a-redirect-to-a-text/m-p/664789#M198660</guid>
      <dc:creator>jmspy</dc:creator>
      <dc:date>2020-06-24T21:20:18Z</dc:date>
    </item>
    <item>
      <title>Re: Call System to run a python program with a redirect to a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Call-System-to-run-a-python-program-with-a-redirect-to-a-text/m-p/664791#M198662</link>
      <description>&lt;P&gt;I attempted the method you posted, and I receive this error in the output:&lt;/P&gt;&lt;PRE&gt;raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)&lt;/PRE&gt;&lt;P&gt;My assumption is that the way I am redirecting the source file could be the culprit, especially since it works perfectly in terminal:&lt;/P&gt;&lt;PRE&gt;done &amp;lt; /mydirectory/sourcefile.txt&lt;/PRE&gt;&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jun 2020 21:45:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Call-System-to-run-a-python-program-with-a-redirect-to-a-text/m-p/664791#M198662</guid>
      <dc:creator>jmspy</dc:creator>
      <dc:date>2020-06-24T21:45:46Z</dc:date>
    </item>
    <item>
      <title>Re: Call System to run a python program with a redirect to a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Call-System-to-run-a-python-program-with-a-redirect-to-a-text/m-p/664855#M198683</link>
      <description>&lt;P&gt;See if your SAS session can read the file.&amp;nbsp; Try reading the first 10 lines.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  infile '/mydirectory/sourcefile.txt' obs=10;
  input;
  list;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Jun 2020 03:20:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Call-System-to-run-a-python-program-with-a-redirect-to-a-text/m-p/664855#M198683</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-06-25T03:20:53Z</dc:date>
    </item>
  </channel>
</rss>

