0

This is my code. I'm pretty new to this.

from subprocess import call
call(["cd", "/etc/apache2/"])

However, when this function is run, I get

Errno 2: No such file or directory

I am running Django within Apache*. This is my views.py file. Ask for additional code, and you shall receive.

edit - It should be noted that /etc/apache2/ does indeed exist.

3
  • please describe what are you trying to achieve here Commented Jun 19, 2014 at 13:07
  • I'm trying to issue a command to the command line, namely the cd folderpath command. I'm beginning to suspect that this is not the way! Commented Jun 19, 2014 at 13:10
  • it definitely is not as it will have no effect at all. Commented Jun 19, 2014 at 13:28

2 Answers 2

1

If you want to change the working directory of the Python process you can use chdir from the os module:

import os

os.chdir('/etc/apache2')
Sign up to request clarification or add additional context in comments.

1 Comment

This is better, thank you. However, I need to write this to command line as I'm modifying the htpsswd file in Apache with a new user that is being registered. I will use this in another clause, though, which does not rely on the command line.
0

First of all, you will not get what you expect if you run this. Try

import os
os.chdir('/etc/apache2')

Second, try /path/to/cd as process may not know cd alias.

1 Comment

Thanks, but I need to issue commands to the command line itself. The working directory of Python is not what I need.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.