Python Forum
Problem keeping the window up
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem keeping the window up
#1
Hi I'm no coder I'm teaching my self python just for the fun of it. So forgive me if the is a ridiculous question but here goes.
What I'm trying to do is have one program open another in terminal. I came up with something that works, but the terminal window closes as soon as you enter a input. If I open the my_file Program manually in Terminal I can make as may entries as I wish, but if I use starter.py the window closes after the first entry.

This is the starter.py
#!/usr/bin/python3

import subprocess
subprocess.run(["gnome-terminal","--","my_file"])
This is my_file.py
#!/usr/bin/python               
while True:
    ds= str(input())
 
These obviously are not the programs I'm working on, they are just to demonstrate what I'm talking about.
Oh if it makes a difference I'm a Linux user ubuntu to be precise.
Thanks for any help Smile
Reply
#2
Well, I've never done that, and I'm new too, but I see that in my_file there is a loop, and in starter.py, unless there is in subprocess.run, the code will run out and terminate.
Reply
#3
Thanks for the reply michael1789.

I left it that way deliberately as I wanted it to run out after it has started the other file. But while trying to figure this out I did try it with a loop there to see if it made a difference, it didn't seem to.
Reply
#4
If it's not looping or waiting for an input, it's done. If you want to give and input, have it process it and ask for another input you have to tell it to do that. my_file is asking you to define ds again and again.

If you want to go back and forth they aren't 2 programs, they are 2 parts of 1 program.

You'll maybe do better with a main.py that imports both those files and allows you to go in between. The so long as you keep main.py running your widow will stay open. Posting what is in your actual files would make it much easier to understand what you are trying to do.

What I suggest is something like this:
# main.py

import subprocess

while True:
    
    ds= str(input())
    subprocess.run(["gnome-terminal","--","ds"])
Then when one ends the other starts, then back to the other and so on.
Reply
#5
I think you misunderstand what I'm trying to do I'm not trying to start the program and pass inputs back and forth. What I'm trying to do is just start a program that will then run independently of the other. I may be using entirely the wrong approach for this, as I said I'm no expert. If there a right way to do this i would really appreciate some help.
Reply
#6
Try this to see if helps, both programs wont exit until we input match word defined in if block, and both act independent.

#starter.py

import subprocess
import os
from subprocess import Popen, CREATE_NEW_CONSOLE
wd=r'C:\Users\testuser\Downloads\DL\testscript.py'
subprocess.Popen(["python","--",wd],shell=False,creationflags=CREATE_NEW_CONSOLE)
print("you are still continuing on program window 1")
while True:
	ds= str(input())
	if ds.lower()=="quit_window_1":
		break
	else: 
		pass
#testscript.py

#!/usr/bin/python 
print("You are on another script run window\n")              
while True:
	ds= str(input())
	if ds.lower()=="quit_window_2":
		break
	else: 
		pass
Best Regards,
Sandeep

GANGA SANDEEP KUMAR
Reply
#7
@sandeep_ganga
Your approach is still not as per asked by @benlyboy
Reply
#8
(Jan-23-2020, 12:00 PM)benlyboy Wrote: I think you misunderstand what I'm trying to do I'm not trying to start the program and pass inputs back and forth. What I'm trying to do is just start a program that will then run independently of the other. I may be using entirely the wrong approach for this, as I said I'm no expert. If there a right way to do this i would really appreciate some help.

My bad. Maybe there is a better way, but if you write your 2 programs and then convert them to .exe files you can run them independently. Sorry I couldn't be more help. I didn't understand.
Reply
#9
Thanks for all the reply's
I think it might people to understand what I want, if they understand my long game in asking this question.

I have written a media backup program for my media system. it works great.

It is actually Two programs one is the backend, it runs invisibly in the back ground, the other is the front end, you open this up just to make changes to setting, or to check the log file, and a few other things. when you're done you close it down and the back end continues running in the back ground. As things work now you have to first open the backend then open the front end when you first fire the program up, or after a system shut down, or the like.

What I would like to do is have it so that when you fire up the frontend it will look to see if the backend is running and if its not, then it would start it, leaving the backend running after the frontend has been closed.

So I want to be able to start one completely separate program from with in another and leave it running after ending the first.
Reply
#10
i am need to python coding. Just wrote code to filter the first column of pvs output and redirect to one file.
below is my code .while running i am getting error variable value not giving output
from sys import stdin
import os
import sys
import subprocess
import shutil
import datetime
#import commands
today = datetime.datetime.today()
global vgname
vgname=raw_input("enter the vgname: ")
cmd='(pvs | grep + vgname) | (awk \'{print $1}\') > sel.txt'
os.system(cmd)

[[email protected] Python-3.6.3]# python rack.py
enter the vgname: vg01
grep: vgname: No such file or directory
[[email protected] Python-3.6.3]#
Some one please help me to fix this
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  merging lists, dedup and keeping order, in older pythons Skaperen 3 1,564 Oct-19-2018, 01:30 AM
Last Post: ODIS
  Keeping Intersection of an Image Only Anysja 4 1,513 Aug-15-2018, 09:47 PM
Last Post: Anysja
  help with keeping score W3BL3Y 2 3,528 Apr-29-2018, 01:12 PM
Last Post: W3BL3Y

Forum Jump:

User Panel Messages

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