0

I am studying automate the boring stuff with python book and therein after finishing the password locker project it is suggested to create a batch file using the following codes:

@py.exe C:\Python34\pw.py %*
@pause

and I did exactly the same mine one looks like this (copied entire script if there are any other potential errors):

import sys
import pyperclip 
    """ PASSWORD LOCKER """

passwords = {
    'facebook' : 'password of facebook', 
    'gmail' : 'password of gmail', 
    'quora' : 'password of quora'
}

if len(sys.argv) == 2:
    account_name = sys.argv[1] 
    if account_name in passwords:
        print('Password of [' + str(account_name).upper() + '] has been copied to clipboard.')
        acc_password = passwords[account_name]
        pyperclip.copy(acc_password)
        print('Paste it anywhere')
    else:
        print('There is no name registered with that account name.')    

@py.exe 'C:\py\Automate the Boring Stuff with Python\Data Structures, Dictionary\pw.py' %*
@pause

then saved the file as pw.bat, according to instruction of the book:

With this batch file created, running the password-safe program on Windows is just a matter of pressing win-R and typing pw .

I then followed these steps again and it didn't work fine. Can you please help me with this. Thank you.

NoorNoori
  • 1,082
  • 11
  • 22

1 Answers1

1

Here are troubleshooting steps I'd suggest:

  1. Ensure py.exe exists in environment path of your computer. The book may have installation instructions that may have been skipped inadvertently. If you know py.exe exists on your computer, but when you execute py.exe on opening a command prompt, you may see:

    'py.exe' is not recognized as an internal or external command, operable program or batch file.

    If you see the above message, this implies, you need to do either of the following:

    a. Change your batch file to say:

    `@<drive:\path\to>\py.exe`
    

    where the part <drive:\path\to> is the path to your python executable (py.exe), OR,

    b. Add the path to py.exe to the environment variables. Comprehensive instructions are here for Python 3.

  2. The way you have framed the question seems to suggest that you saved the entire code in one file pw.bat. If you did, you need to ensure the following:

    a. Last two lines of the your code snippet are in a file pw.bat, AND,

    b. Rest of the code is in the file C:\py\Automate the Boring Stuff with Python\Data Structures, Dictionary\pw.py.

  3. The instruction below is correct only if the file pw.bat is in the environment path and thus visible to the operating system:

    With this batch file created, running the password-safe program on Windows is just a matter of pressing win-R and typing pw

    If you do not know whether this is true or not, you will need to find out where you saved pw.bat. Open a command prompt and navigate to that location, and then execute pw. Issues pertinent to this are discussed here.

  • Okay, I guess the second part was the problem. – NoorNoori Jul 31 '19 at 08:27
  • how do I open `.bat` file? I clicked on it there is nothing shown there. Just stating press any key to continue and upon pressing any key it exits the program. – NoorNoori Jul 31 '19 at 08:29
  • Two ways: (a) double clicking (which is what you did). It shows the output followed by what you mention ("press any key to continue") which is the result of @pause, (b) open a command prompt, go to the location where your batch file is (via command 'cd '), run the batch file by typing the name of the batch file. – Code Maverick Jul 31 '19 at 08:46