简体   繁体   中英

Can't get script to run using windows command line with batch file

Environment is correct, but it's not finding my program.

Code for my python program, created using visual studio 2017, located here:
C:\\Users\\Alex\\Python Programs\\pw\\pw .

#! python3
# pw.py - An insecure password locker program.

PASSWORDS = {'email': 'f7nsdkfn2BDD3fkjTXjs6Fjsn',
             'blog': 'fdkNc32NskNskKslLI321n',
             'luggage': 12345}

import sys, pyperclip
if len(sys.argv) < 2:
  print("Usage: python pw.py [account] - copy account password")
sys.exit()

account = sys.argv[1]      # first command line arg is the account name

if account in PASSWORDS:
  pyperclip.copy(PASSWORDS[account])
  print("Password for " + account + " copied to clipboard")
else:
  print("There is no account named " + account)

I then created a .bat file located here: C:\\Users\\Alex\\Python Programs\\pw\\pw

@py.exe C:\Users\Alex\Python Programs\pw\pw\pw.py %*
@pause

I know the environment is set correct as I get python details when typing python in the command line.

But if I type:

pw <luggage>

I get an error saying The syntax of the command is incorrect .

If I type:

python pw

I get this error (null): can't open file 'pw': [Errno 2] No such file or directory .

Not sure what I have done wrong and I have spent way too much time on this now.

I have now changed my batch file to runpw, when I double click this file I get this message:- "'py.exe' is not recognized as an internal or external command, operable program or batch file."

Fixed. I reorganised my files and place them in this folder:- C:\\Users\\Alex\\Python_programs\\Password_project

Having spaces in the file path originally may have been a cause of the issue.

Also make sure you do not save your files as pw.py.py lol

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