简体   繁体   中英

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, eg tested by echo 111 | (set /p readvalue= & set readvalue) echo 111 | (set /p readvalue= & set readvalue) .

Working on Windows 10.

Thank you.

content of foo.py :

print(input())

calling it via:

echo "hello world" | python foo.py

You need input()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM