4
I made a script in Python that runs some commands in the terminal, and I want it to move to another folder.
I tried to use the cp teste.py minha_pasta/teste.py
, but it doesn’t work. This is my code:
def exec_commands(args):
data = args
for f in data:
if f[:2] == 'cd':
if f[3:] == '~':
print(os.environ['HOME'])
os.chdir(os.environ['HOME'])
else:
os.chdir(f[3:])
if len(f) > 0:
cmd = subprocess.Popen(f[:], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE )
output_bytes = cmd.stdout.read()
output_str = str(output_bytes, "utf-8")
exec_commands(["mkdir minha_pasta", "cp teste.py minha_pasta/teste.py"])
And what is the purpose/need to do this for your project"? It seems to me to be a XY problem
– Guilherme Nascimento