Python Forum
control a linux program with python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
control a linux program with python
#1
Hi,
I am not a software devloper.
I started using Python to help me automate some tasks

I have a custom program who run in Linux, in a command window
after launching the program it gives me a menu and I choose the what I want it to do by pressing 1,2,3...etc
some menu gives me access to other menus,
I don't need the result of what the program does (for now)

this program has no argument so just need to "write" on his command window numbers

Thank you
Reply
#2
Not that familiar, but would pipes work to keep it simple?
Reply
#3
do you know some examples how to use it
Reply
#4
Here's a tutorial
https://opensource.com/article/18/8/intr...ipes-linux
Reply
#5
thank you, but I need to control it by python
Reply
#6
Haven't used it by would try Pexpect https://pypi.org/project/pexpect/
Reply
#7
The program you start has no command line arguments to control it?
Does the program only output text or does the program provides a gui in terminal via ncurses (looks like Midnight Commander)?

If the program works in text mode, it should be doable with pexpect.
If the program looks like midnight commander, good luck.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#8
the program has no arguments
the program output text, it gives me a list AND every action from me, requires me to enter a number from this list.
I will try pexpect
thank yoou
Reply
#9
Then pexpect is what you need.
They provide also some examples.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#10
thank you very much

I didn't code almost since the university, I started using Python 2 months ago with simple scripts but very helpful.
It's sometimes hard for me to find the right "way" of doing things.
thank you for both
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is possible to run the python command to call python script on linux? cuten222 6 728 Jan-30-2024, 09:05 PM
Last Post: DeaD_EyE
  How to use a variable in linux command in python code? ilknurg 2 1,599 Mar-14-2022, 07:21 AM
Last Post: ndc85430
  Python syntax in Linux St0rmcr0w 2 50,683 Jul-29-2021, 01:40 PM
Last Post: snippsat
  db migration(db version control) for python lubaz 2 2,758 May-30-2021, 01:36 PM
Last Post: lubaz
  python 3 raspberry pi 4 dual control motor programming problem yome 0 1,975 Mar-21-2021, 05:17 PM
Last Post: yome
  Login to NordVPN on Linux with python script AGreenPig 2 5,967 Feb-09-2021, 10:44 AM
Last Post: AGreenPig
  how to run linux command with multi pipes by python !! evilcode1 2 6,337 Jan-25-2021, 11:19 AM
Last Post: DeaD_EyE
  where to get portable Python for Linux (Fedora)? python001 5 6,300 Nov-01-2020, 05:23 PM
Last Post: Larz60+
  Python in Linux environment on RPI kendias 22 11,064 Sep-05-2020, 03:04 AM
Last Post: K_Research
  How do I pick the right python in Linux env? MDRI 9 3,687 Jun-27-2020, 05:40 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020