0

I have a problem redirecting a pipe output as the second argument of a python script. Basically, my code would be something like that:

sort -u inputfile.txt | python myscript.py Firstargument.txt PIPE_OUTPUT_AS_SECOND_ARGUMENT | other_bash_commands

The problem is shown capitalized above.

As I am quite unexperienced with both bash and python, here is also what my python script looks like:

script, firstargument, mypipeoutput = argv

def myfunction(a, b):
    # <insert well written function here using a and b>

firstarg= open(firstargument)
secondarg=open(mypipeoutput)

myfunction(firstarg, secondarg)

In addition to not working properly, the way I wrote that seems very redundant, so if you have any additional suggestions to make it more straightforward I would be happy to hear them.

user3439894
  • 7,266
  • 3
  • 17
  • 28
Tiana
  • 95
  • 1
  • 1
  • 4
  • Possible duplicate of [Pipe output from shell command to a python script](http://stackoverflow.com/questions/11109859/pipe-output-from-shell-command-to-a-python-script) – Cory Shay Mar 18 '16 at 17:10

1 Answers1

0

It's not entirely clear if this is what you are asking for, but if you want the output of your sort to be given as the second argument to your script, then you want:

python myscript.py FirstArgument "$(sort -u inputfile.txt)" | ...
William Pursell
  • 204,365
  • 48
  • 270
  • 300
  • That seems to work! I was afraid it wouldn't because I actually have two pipes in a row instead of just `sort -u inputfile.txt` , but i just put them as they are in the parenthesis, and tadaaa Thank you a lot! – Tiana Mar 18 '16 at 17:30