I would like to pass the contents of a file along with some other parameters to a python script on windows.
On linux, I can do it like this:
less input.txt | my_script.py > output.txt
On windows I tried the following but it doesn't seem to work:
more input.txt | python my_script.py > output.txt
Any idea what I'm doing wrong?
Python sys module stdin is used by the interpreter for standard input. Internally, it calls the input() function. The input string is appended with a newline character (\n) in the end. So, you can use the rstrip() function to remove it.
How to pass information to a Python script using the sys. argv command by hard-coding the input variables in Jupyter Notebook or through the interactive use of the input() function.
Opening Files in PythonPython has a built-in open() function to open a file. This function returns a file object, also called a handle, as it is used to read or modify the file accordingly. We can specify the mode while opening a file. In mode, we specify whether we want to read r , write w or append a to the file.
This can be done by passing a comma-separated list of file names as one of the arguments while running the script. FOr example, if you have a script called `myscipt.py' you would run it as: python myscript.py file1,file2,file3.
Use following command. It works both in Linux and Windows.
python my_script.py < input.txt > output.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With