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.

1

1 Answer 1

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)" | ...
Sign up to request clarification or add additional context in comments.

1 Comment

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.