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

PASSWORDS = {'email': 'F7minlBDDuvMJuxESSKHFhTxFtjVB6',
              'blog': 'VmALvQyKAxiVH5G8v01if1MLZF3sdt',
               'luggage': '12345'}

import sys, pyperclip

if len(sys.argv) < 2:
    print('Usage: py 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 really don't know what to do. After running win+r and typing e.g. pw email i get only 'usage:py bla bla bla.. nothing else whatever i wrote in win+r

the bat file is like:

'''call C:\Users\Rostek\anaconda3\Scripts\activate.bat
C:\Users\Rostek\anaconda3\python.exe "C:\Users\Rostek\.spyder-py3\Projekty\pw.py"
@pause'''

I cannot pass the arguments I think. I have read all the internet and found nothing like this. please help. It's program from the book. I am using anaconda3.

Rostkov
  • 11
  • And the usage is telling you something right? You have to pass in the account type or name after pw.exe. Try this, open a cmd prompt and type `python full/path/to/pw.exe email`. – Devon Horizon Jul 13 '20 at 12:43
  • so is there a chance that i would work by win+r and typing NameOfProgram e.g.email? Because i know that it should work and people got it. – Rostkov Jul 13 '20 at 12:51
  • Type what I said after win+r, should work if everything's set up properly – Devon Horizon Jul 13 '20 at 13:01
  • why does it work on anaconda prompt and not in Win+r as rest of programs...Because of the argument? – Rostkov Jul 13 '20 at 13:02
  • It works with "pw.py" but the cmd window only blinks for a moment and there is no info that it copied the password as it should do... – Rostkov Jul 13 '20 at 13:07
  • It closes after the program finishes, this is one of the reasons you don't run scripts from there. – Devon Horizon Jul 13 '20 at 13:14
  • Heh, thanks for involvement but it didn't solve my problem yet:( maybe i have some problems with system variables? – Rostkov Jul 13 '20 at 13:37

1 Answers1

0

You might want to think about what your problem is supposed to do.

if len(sys.argv) < 2: print('Usage: py pw.py [account] - copy account password') sys.exit()

This clearly does what it should. Your question is actually not about python, but about win+r passing arguments.

Why do you want to run your program with win+r in the first place?

After running win+r and typing e.g. pw email...

What you want is to open the command line/ powershell/ bash instead and simply pass the variables to your programm with python3 programname.py email directly. If you want to do that even cleaner you should use an argparser.

EDIT:

After the clarification in the comments:

The problem is that if you execute a script with win+r you will get the output- for a fraction of a second- then the cmd is closed...

So unless you specify a location in your script to where the pw is written to, you´ll have it in your console. Which blinks and vanishes immediately. Therefore open a console and execute the program from there. Or you might want to have a look at this: Output to clipboard

Arbor Chaos
  • 149
  • 6
  • so is there a chance that i would work by win+r and typing NameOfProgram e.g.email? Because i know that it should work and people have it worked. – Rostkov, sorry for language. – Rostkov Jul 13 '20 at 12:52
  • "Why do you want to run your program with win+r in the first place?" because its faster, thats all – Rostkov Jul 13 '20 at 13:10