abhinav
6 years agoNew Contributor
Calling another script using subprocess.call method in python script
Hi Team,
we have requirement to call script from current python script.to call another script i’m using subprocess.call method.
subprocess.call(r"C:\Python27\python.exe" + " " + r"C:\Test\Scripts\Test.py" , shell=True)
but i’m not receiving any error nor any result and pipeline goes on executing continuously without giving any result or error.
python code :-
Import the interface required by the Script snap.
from com.snaplogic.scripting.language import ScriptHook
import java.util
import subprocess
class TransformScript(ScriptHook):
def init(self, input, output, error, log):
self.input = input
self.output = output
self.error = error
self.log = log
# The "execute()" method is called once when the pipeline is started
# and allowed to process its inputs or just send data to its outputs.
def execute(self):
self.log.info("Executing Transform script")
while self.input.hasNext():
try:
# Read the next document, wrap it in a map and write out the wrapper
in_doc = self.input.next()
record = in_doc
subprocess.call(r"C:\\Python27\\python.exe" + " " + r"C:\\Test\\Scripts\\Test.py" , shell=True)
#subprocess.call("C:\\Python27\\python.exe" + " " + "C:\\Test\\Scripts\\Test.py" , shell=True)
self.output.write(record)
except Exception as e:
errWrapper = {
'errMsg' : str(e.args)
}
self.log.error("Error in script")
self.error.write(errWrapper)
self.log.info("Finished executing the Transform script")
The Script Snap will look for a ScriptHook object in the “hook”
variable. The snap will then call the hook’s “execute” method.
hook = TransformScript(input, output, error, log)
can someone suggest what i’m doing wrong.