Jhonny
Jhonny

Reputation: 618

Pipe password to prompt in batch file

I am using a Python script to query data via an API which requires authentication. That script prompts the user for the input of a password (no other input required). I want to automate this workflow using the Windows Scheduler and thus need to automatically provide the password upon the prompt in automate.bat file.

However, the pipe is simply not recognized. I tried the following MWE:

foo.py

from getpass import getpass
password = getpass()
print(password)

automate.bat:

echo PWD | python foo.py

There is no difference to executing python foo.py directly; both times, I need to provide the password. The pipe works otherwise fine, e.g. tested by echo 111 | (set /p readvalue= & set readvalue).

Working on Windows 10.

Thank you.

Upvotes: 1

Views: 656

Answers (1)

Tin Nguyen
Tin Nguyen

Reputation: 5330

content of foo.py:

print(input())

calling it via:

echo "hello world" | python foo.py

You need input()

Upvotes: 1

Related Questions