Python Forum
Capturing inputs values from internal python script
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Capturing inputs values from internal python script
#3
Hi,

First thanks for your feedback.
I don't import other scripts or use the classes, those are black box separated scripts.
Till now I used methods like subprocess.getoutput(cmd) or check_output(..)
as the following:
try:
		data = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT) 
		exitCode = 0
except subprocess.CalledProcessError as ex:
		data = ex.output
		data2 = ex.cmd
		exitCode = ex.returncode
		writeToAll(logfile, "Command:\n " + str(cmd) + "\nResult:\n Error occurred: " + str(data) + " exit code: " + str(exitCode) + "(0 for SUCCESS). Build will exit.", loggingLevel )
		writeInfoToLog( logfile, "---------------------------------------------------------------------------------------------")
		if exitOnError:
			exit(exitCode)
	if data[-1:] == '\n':
		data = data[:-1]
	return data, exitCode
But this won't serve me now in others (I am just a python beginner, not an expert). I will add an example to explain my problem.
#child.py
#!/usr/bin/env python

import sys
# 
print('Enter user:')
user = input()
print('Enter password:' )
passwd = input()
print('Enter tag:')
tag = input()
#Parent.py
...
p = subprocess.Popen([PYTHON, "-i", "./child.py"], stdout=subprocess.PIPE, stdin=subprocess.PIPE, shell=True)
(output, err) = p.communicate()
...
Don't know how to continue from here to pass the input parameters user inserted in child.py.

Hope this explains it.
Please advice,
Thank you for your help,
Limor
Reply


Messages In This Thread
RE: Capturing inputs values from internal python script - by limors11 - Jun-16-2019, 12:03 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Capturing BS4 values into DF and writing to CSV cubangt 18 2,096 Sep-05-2023, 01:57 PM
Last Post: cubangt
  capturing multiline output for number of parameters jss 3 870 Sep-01-2023, 05:42 PM
Last Post: jss
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,471 Jun-29-2023, 11:57 AM
Last Post: gologica
  Json filter is not capturing desired key/element mrapple2020 1 1,197 Nov-24-2022, 09:22 AM
Last Post: ibreeden
  Trying to use 2 values from excel in my script but getting error.. cubangt 3 1,727 May-11-2022, 07:12 AM
Last Post: normanwolf
  web socket server handle onnection closed abnormally [internal]) korenron 0 2,180 Sep-23-2021, 09:26 AM
Last Post: korenron
  500 internal server error Nitil 1 2,939 May-01-2021, 06:16 PM
Last Post: snippsat
  How to kill a bash script running as root from a python script? jc_lafleur 4 6,025 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur
  Removing internal brackets from a string Astrikor 4 2,774 Jun-04-2020, 07:54 PM
Last Post: Astrikor
  crontab on RHEL7 not calling python script wrapped in shell script benthomson 1 2,365 May-28-2020, 05:27 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

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