Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Program-launching script will not close until the program it launches is closed
#1
I wasn't sure whether to post this in "General Coding Help" or "GUI", as I'm encountering the problem in a tkinter-based GUI script, but I think the issue is my limited understanding of subprocess.run(), so I thought I'd post here.

What I've written is a script that creates, populates, and saves a spreadsheet, then launches libreoffice Calc and loads the saved file, using subprocess.run(). What I want is for the python script when executed to finish and exit, closing the GUI and leaving the spreadsheet running - in essence, I'd like the script to "launch the desired program and then quit." What's happening instead the spreadsheet launches and loads its data file just fine, but the python script continues running until you close the spreadsheet. I'm wondering whether I need some additional argument to subprocess.run() to fork off a new process in which to run the spreadsheet, or something of that sort.

I've posted only the code that launches the spreadsheet, loads the saved file, and exits, for the sake of brevity.

Any idea what I'm missing.

root = Tk()
# (code omitted for brevity)
# The result have already been written into an .xlsx file, the name of which is stored in saveFileName
run_argList = ["C:\\Program Files\\LibreOffice 5\\program\\scalc.exe",saveFileName]
x = subprocess.run(run_argList)
root.quit()
Quote
#2
As described, you can't, because when a process exits, all its child processes are killed.

So the trick is therefore to have the new process started by the desktop process, which remains up until the user logs off. IIRC in Windows this is what the START command does, so you would use, if start is a distinct executable:
run_argList = ["start","C:\\Program Files\\LibreOffice 5\\program\\scalc.exe",saveFileName]
or if start is a built-in command to cmd.exe 
run_argList = ["cmd.exe","/c" "start","C:\\Program Files\\LibreOffice 5\\program\\scalc.exe",saveFileName]
in which cas you can likely simplify this to:
run_argList = ["cmd","/c" "start","scalc",saveFileName]
and let cmd.exe figure out what/where scalc is.

Btw, you can divide by two the wear of your backslash key in several ways:
  1. use a "raw" string specification by prefixing the string with r
    r"C:\Program Files\LibreOffice 5\program\scalc.exe"
  2. use a "raw" string specification by using triple quotes
    '''C:\Program Files\LibreOffice 5\program\scalc.exe'''
  3. learning that Windows is perfectly happy with forward slashes(only the CMD.EXE argument parser doesn't like them)
    'C:/Program Files/LibreOffice 5/program/scalc.exe'
    (of course if you use cmd.exe in the call above you can't use that form, but you normally don't need the path).
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Python basic program webshakeup 1 31 3 hours ago
Last Post: Larz60+
  Program Functions Disabled Doffer 0 99 Sep-14-2019, 07:35 PM
Last Post: Doffer
  How ad key unlocker program to code? storzo 8 185 Sep-04-2019, 11:55 PM
Last Post: micseydel
  Learn to program with Minecraft SheeppOSU 11 1,410 Aug-10-2019, 12:28 AM
Last Post: railhead
  Song Modifying Program Starting Point BadenJaden 0 124 Jul-30-2019, 11:28 PM
Last Post: BadenJaden
  How do I set the path to my module one directory below my python 3.7.3 program? deac33 1 114 Jul-30-2019, 04:13 AM
Last Post: Larz60+
  Problem: Once I cancel the process my program will start working! Hadad 0 106 Jul-24-2019, 04:09 PM
Last Post: Hadad
  Facing issue with pyautogui program after PC upgrade Utkarsh29 2 191 Jul-15-2019, 05:20 PM
Last Post: Utkarsh29
  Store a product/item in a inventory program viktoria_linn 1 170 Jul-02-2019, 09:26 PM
Last Post: DeaD_EyE
  Need help executing a program 1234kevind 2 251 Jun-28-2019, 02:51 PM
Last Post: 1234kevind

Forum Jump:


Users browsing this thread: 1 Guest(s)