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

user1583546
  • 11
  • 1
  • 1
  • [enter link description here](https://stackoverflow.com/a/17658680/8794595) Pythons standard input is probably the correct approach – user290710 Feb 24 '21 at 16:08

2 Answers2

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.

Vasili Syrakis
  • 9,321
  • 1
  • 39
  • 56
-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
  • You can use a `|` to pipe from stdout of `cat` into a python program as the OP suggested. – lachy Apr 06 '19 at 22:49