I'm a new python user and I'm trying to create a python program that will run on a targate and communicate with the terminal.
The main idea is to run several commend and short programs and analyze the results.
for example running those 2 commands:

cd /home/user/folder
ls | grep filename

and if file name existed in the folder know it and continue according to it.

for some reason I'm unable to find the way to communicate with the terminal throw python or by using Pexpect.

If you may please assist me in finding the commends that will allow me do this I will really appreciate it :-)

Thank allot!

Recommended Answers

All 4 Replies

Please post your code so that we can help you.

As I wrote I'm new to Python and this is the first time I try to write except the exercises at the tutorial...
I don't seem to be able to write anything to the terminal at all...
I was hoping you will be able to give me a lead on how to start so I will be able to continue from there.
I tried using spawn but it seem to be useless for terminal - or I couldn't find how to direct it to the terminal.

Why don't you use python's functions to access the file system ? A good pythoneer would write

import os

if os.path.exists(filename):
  do_something() # we know the file exists
  do_something_else() # we know the file doesn't exist

This is great help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.