Python Forum
Executing external Python file in background and get output in python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Executing external Python file in background and get output in python
#1
I have an python file that takes some inputs and print outputs according to these inputs. I am try to execute this script in another script. All I need to do is sending some parameters to this file and getting the outputs in this script.

The script that I need to be executed :

while True:
  print("Sabah 1")
  print("Oglen 2")
  print("Aksam 3")
  print("Gece 4")
  print("---------")


  secim = raw_input("Gun icerisindeki zaman dilimini giriniz")

  isim = raw_input("Isminizi giriniz.")


  if (secim=='1') : 
      print("Gunaydin"+isim)
  elif (secim == '2'):
      print("Tunaydin"+isim)
  elif (secim == '3'):
      print("iyi aksamlar"+isim)
  elif (secim == '4'):
      print("Iyi geceler"+isim)
  else:
      print("Program sonlandiriliyor")
      break
The script that should execute the script above :

import subprocess, threading, time
can_break = False

def run():
    args = ['python','odev2.py','arg1','arg2']
    popen = subprocess.Popen(args,shell=False,stdout=subprocess.PIPE)
    while not can_break:
        print(popen.stdout.readline())


t = threading.Thread(target=run)

try:
    t.start()
    while True: 
        print('Main Thread.... ')
        time.sleep(1)
except KeyboardInterrupt:
    can_break_break = True
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Unexpected Output - Python Dataframes: Filtering based on Overlapping Dates Xensor 5 654 Nov-15-2023, 06:54 PM
Last Post: deanhystad
  Syntax error while executing the Python code in Linux DivAsh 8 1,451 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  programming OpenOffice with External Python Project bobthebuilder44 1 732 Apr-07-2023, 06:02 AM
Last Post: buran
  Compiles Python code with no error but giving out no output - what's wrong with it? pythonflea 6 1,469 Mar-27-2023, 07:38 AM
Last Post: buran
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,046 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  Python Pandas Syntax problem? Wrong Output, any ideas? Gbuoy 2 883 Jan-18-2023, 10:02 PM
Last Post: snippsat
  Python VS Code: using print command twice but not getting output from terminal kdx264 4 1,033 Jan-16-2023, 07:38 PM
Last Post: Skaperen
  Function not executing each file in folder mathew_31 9 2,167 Aug-22-2022, 08:40 PM
Last Post: deanhystad
Question Export Python output to Excel skyline1397 1 1,984 Jun-26-2022, 05:10 AM
Last Post: skyline1397
  Writing to External File DaveG 9 2,409 Mar-30-2022, 06:25 AM
Last Post: bowlofred

Forum Jump:

User Panel Messages

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