0

Hello I am trying to pipe the input from a data file as command line input using power shell.

I am using the command cat D:\Python\test-inputs.txt| python a3p1.py

The output should be outlying the process from the file. I am reading my stdin input with

while True:
    line = sys.stdin.readline()
    if not line:
        break
    words = line.split()
    for word in words:
        breakdown(database, word)

Can anyone help me

1

2 Answers 2

0

It might be a bit cleaner to do something like this:

foreach ($line in (cat inputs.txt) {
    python a3p1.py $line
}

and then you can code your python script to accept arguments which will be in the format of the lines you are inputting.

Although you could just write your python file to read the file in too.

Sign up to request clarification or add additional context in comments.

Comments

-1

It's a little unclear what you're asking.

You probably want to use

cat D:\Python\test-inputs.txt > a3p1.py

| is for piping STDOUT from a program into another program's STDIN, > is for piping STDOUT (from cat in this case) into a file.

Alternatively, to use test-inputs.txt as STDIN for your python program, you can use:

python a3p1.py < test-inputs.txt

1 Comment

You can use a | to pipe from stdout of cat into a python program as the OP suggested.

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.