-1

I'm running into a question, there is data file I need to process, let's name it Data.data. I need to process this data file in two steps, each of them is in a separate python .py file.

The first step (Let's name it first.py) takes the Data.data as input and output into a .txt file named output1.txt(output1.txt is generated by first.py); then the second step (Let's name it second.py), takes the output1.txt as input and print the results.

Both python file take inputs with sys.argv[1].

I'm trying to write a .sh file to do the job listed above (Data.data, first.py and second.py are in the same directory) --- first process Data.data with first.py, this should generate output1.txt, then run second.py with output1.txt as input and print the result with python's own print function.

Could anyone show me how to do this? I spent a lot of time trying to code this up and I'm really stucked. I can write a .sh that run 2 .py at the same time but not like this situation, please save me, thank you very much!

A.Y
  • 137
  • 1
  • 9
  • 1
    Can you show what have you done in code so far so it would be easy to point out where you're getting stuck? – Nitin Prakash Feb 24 '20 at 05:09
  • 1
    Could you show us or elaborate what is in first.py and second.py? Is the reading/writing from output1.txt hardcoded, or do you want to have the filename as an argument? – wxker Feb 24 '20 at 05:09

1 Answers1

1

This link will help.

I have tried doing it this way

I Created two files a.py and b.py

a.py

f= open("test.txt","w+")
for i in range(10):
 f.write("This is line %d\r\n" % (i+1))
f.close();

b.py

f=open("test.txt", "a+")
for i in range(2):
 f.write("Appended line %d\r\n" % (i+1))
f.close()

and then I have my shell script

try.sh

#!/usr/bin/env bash
python a.py && python b.py

it first creates the file as instructed in file a.py and then appends that file as instructed in file b.py.

yousuf iqbal
  • 408
  • 2
  • 7
  • 16