-
-
Notifications
You must be signed in to change notification settings - Fork 34.6k
Expand file tree
/
Copy pathunderstand_shutil.py
More file actions
49 lines (32 loc) · 1.21 KB
/
understand_shutil.py
File metadata and controls
49 lines (32 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import subprocess
from subprocess import Popen
import shlex
print("""\ncalling 'shlex.quote("for")'""")
subprocess.call(shlex.quote("for"), shell=True)
print("""\ncalling 'shlex.quote("'for'")'""")
subprocess.call(shlex.quote("'for'"), shell=True)
print("""\ncalling "'for'" """)
subprocess.call("'for'", shell=True, env={'PATH': '.'})
print("""\ncalling "for" """)
subprocess.call("for", shell=True, env={'PATH': '.'})
# import os, shlex, shutil, subprocess
# open("do", "w").write("#!/bin/sh\necho Something is being done...")
# os.chmod("do", 0o700)
# subprocess.call(shlex.quote("'./my_command'"), shell=True)
# subprocess.call("'my_command'", shell=True, env={'PATH': '.'})
# subprocess.run(shlex.quote("do"), shell=True, env={'PATH': '.'})
# print(shlex.quote("my_command"))
2
# p = Popen(shlex.split("mycommand"), shell=False, executable="/bin/bash")
# print(p)
# test = shlex.quote("done")
# print(test)
# class MyError(Exception):
# def __init__(self):
# print("Hello")
# class SomeProcessError(MyError):
# def __init__(self, returncode):
# self.returncode = returncode
# def __str__(self):
# return f"Died with returncode: {self.returncode}"
# raise SomeProcessError(3)