Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8169781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:57:22+00:00 2026-06-06T20:57:22+00:00

I was going through the pexpect documentation and it said You can call the

  • 0

I was going through the pexpect documentation and it said You can call the run() function to execute a command and return the output

so i did the following but it errored out. Am i missing something here?

>>> pexpect.run('pwd')
'/home/vijay\r\n'
>>> pexpect.run('cd /home')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/pexpect.py", line 219, in run
    child = spawn(command, maxread=2000, logfile=logfile, cwd=cwd, env=env)
  File "/usr/lib/python2.7/dist-packages/pexpect.py", line 429, in __init__
    self._spawn (command, args)
  File "/usr/lib/python2.7/dist-packages/pexpect.py", line 516, in _spawn
    raise ExceptionPexpect ('The command was not found or was not executable: %s.' % self.command)
pexpect.ExceptionPexpect: The command was not found or was not executable: cd.
>>> 

I’m writing a script on which I download a git repository and wanted to perform cd (to that repository) and then pass on some command. so I have decided to use pexpect module since it provides interactive console

Let me know if I’m missing anything here?

Thanks,
-Vijay

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T20:57:23+00:00Added an answer on June 6, 2026 at 8:57 pm

    cd is a builtin function of your shell. You can run whatever command you want to do in whatever directory you want to using the run() methods cwd keyword arg:

    pexpect.run("pwd", cwd="/home")
    

    For more information check the API docs at: http://pexpect.sourceforge.net/pexpect.html

    Alternatively you can use Python’s os.chdir() function to change the current working directory before you execute the pexpect run method:

    os.chdir("/home")
    pexpect.run("pwd")
    

    See: http://docs.python.org/library/os.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Going through Javascript documentation, I found the following two functions on a Javascript object
While going through a WP7.5 background transfer service policy, one can read the following:
Going through K&R I saw the following code snippet of a function, strcopy, which
Going through happstack-lite tutorial : we build functions that have return type of ServerPart
Going through some documentation on modifying CGImageRef data, I came across a strange example
While going through Effective C++ (by Scott Meyers), I came across the following code
While going through a Zend tutorial , I came across the following statement: Note
Going through the documentation of the SDF, i found many classes like the BitmapEx
While Going through the java tutorial on sun site, I see following piece of
I was going through the SOQL documentation , but couldn't find query to fetch

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.