wpenfold
5 years agoContributor
How do I debug a python script in the script snap
I am using a script snap to use SSH to call a procedure on another server. The pipeline completes without error, but it’s not calling the procedure–and it’s not giving me any error messages, so I don’t know what is failing. Is there a way to view the log that is produced and/or some other method to debug the script?
from com.snaplogic.scripting.language import ScriptHook
from com.snaplogic.scripting.language.ScriptHook import *
from subprocess import Popen, PIPE
import subprocess as subprocess
class TransformScript(ScriptHook):
def init(self, input, output, error, log):
self.input = input
self.output = output
self.error = error
self.log = log
def execute(self):
self.log.info("Executing Transform script")
while self.input.hasNext():
data = self.input.next()
cmdstr = " " + str(data['cmd']) + " "
# args = [cmdstr]
# proc = Popen(["ssh", "banjobs@server01.campus.ithaca.lan", " pwd "], shell=False, stdout=PIPE, stderr=PIPE)
proc = Popen(["ssh", "banjobs@server01.campus.ithaca.lan", " touch /u01/appworx/wjptest.txt "], shell=False, stdout=PIPE, stderr=PIPE)
# proc = Popen(["ssh", "banjobs@server01.campus.ithaca.lan", cmdstr ], shell=False, stdout=PIPE, stderr=PIPE)
out, err = proc.communicate()
exitcode = proc.returncode
proc.kill()
self.output.write(out)
self.log.info("Finished executing the Transform script")
hook = TransformScript(input, output, error, log)