0

I am trying to execute a program from a directory

import os
os.chdir("/home/user/a/b")
with cd("/home/user/a/b"):
    run ("./program")

i get cd is not defined... any help appreciated cheers

2 Answers 2

1

I'm not sure what instructions you're following to get what you showed. There is no built-in function called cd or run in Python.

You can call a program in a specific directory using the subprocess module:

import subprocess

subprocess.call("./program", cwd="/home/user/a/b")

The cwd argument causes the call function to automatically switch to that directory before starting the program named in the first argument.

Sign up to request clarification or add additional context in comments.

1 Comment

appreciate the speedy help :D
0

It looks like you are trying to use functionalities of fabric. Make sure fabric is installed, and cd and run are imported from fabric. Something like,

from fabric.context_managers import cd
from fabric.operations import run
import os
os.chdir("/home/user/a/b")
with cd("/home/user/a/b"):
    run ("./program")

Save your file as fabfile.py,and from the same directory run it as:

fab -H localhost

For more information on the fabric, checkout: fabric

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.