0

When I echo a txt document and my service works perfectly, i use the terminal. Here is the command that works: echo $(<piece.txt ) | nc 127.0.0.1 9988

When I try to do the same command in python using os. os.system("echo '$(<piece.txt )' | nc 127.0.0.1 9988")

I have tried all kinds of parenthesis options and different options that wont work.

My preference is to actually echo a string variable. If someone can help me either echo a text doc or echo a string variable it would be much appreciated! Thanks :)

1
  • Why would you use os.system() for that at all? Use the Python socket library and you won't have any need for nc in the first place. Commented Feb 18, 2021 at 2:25

1 Answer 1

2

I'm guessing that's because echo $(<piece.txt) is a bashism and will work only in some shells.

I'm not sure of what is in piece.txt. Maybe you could do something like:

os.system("echo $(cat piece.txt) | nc 127.0.0.1 9988")

Maybe it's possible to use redirections as well:

os.system("nc 127.0.0.1 9988 < piece.txt")
Sign up to request clarification or add additional context in comments.

1 Comment

I ended up getting it to work with something like this -

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.