0

Hello,
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!

3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by R2605
0

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.
Thanks

0

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

import os

os.chdir("/home/user/folder")
if os.path.exists(filename):
  do_something() # we know the file exists
else:
  do_something_else() # we know the file doesn't exist

Edited by Gribouillis: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.