0
  • there is a hacking challenge.
  • i have a password protected file called "lock"
  • opening file with password returns a QR-code.
  • need to assign QR to a var.
  • Don't want to display QR everytime

Works but has output:

var = os.system("./lock %s" % password)

SO says i should use:

var = subprocess.Popen("something.py")

tryied to pass like above but that fails cause "Popen" wants a list or a string. if i concat the command as a string before using popen, its still displayed.

what a already read (at least)

Suppress output of subprocess Passing Variables to Subprocess.Popen How to just call a command and not get its output

full code:

import sys
import os
import subprocess

def file_len(fname):
with open(fname) as f:
    for i, l in enumerate(f):
        pass
    return i + 1

   lock = "/root/share/lock"
   print "Hello"
   passfile = raw_input("Enter the password file name: ")
   assert os.path.exists(passfile), "I did not find the file at, "+str(passfile)
   devnull = open(os.devnull, 'wb')
   trys = file_len(passfile)
   passfile = open(passfile,'r+')
   cnt = 1
   wrong = os.system("./lock penis")

   for password in passfile:
   #       com = ("./lock %s" % password)
   #       var = os.system("./lock %s" %  password)
   var = subprocess.Popen("./lock  %s" % password, stderr=devnull, stdout=devnull)

   if var == wrong:
            os.system('clear')
            cnt += 1
            print ("Try  %s/%s " %(cnt, trys))
            print ("Currently PIN: %s" % password)
    else:
            print "!!!!!!!!!!!!!!!!!"
            print password

redirecting to devnull doesn't work either. OSError: [Errno 2] No such file or directory: ''

Cœur
  • 37,241
  • 25
  • 195
  • 267
cuilster
  • 123
  • 1
  • 12

1 Answers1

0

I suggest you try using os.devnull directly as target instead of opening as file. I believe you are getting the error in null

devnull= open(os.devnul, 'wb')

The reson will be because /dev/null is rather a placeholder for sending to nothing(the void) rather than an actual file you can open.

Abhishek P
  • 189
  • 2
  • 9