I am trying to execute python script using a JSch, what I want is to run the python script from a .sh file using a different interpreter (shebang).
Here is the content of my shell script file (fileExec.sh):
#!/usr/bin/env python
print 'hello from python'
It looks like the shebang cannot be changed since I getting:
bash : print command is not found
Here is my Java code:
session = newSessionFor(user, host, port);
Channel channel = session.openChannel("exec");
File shFile = new File("fileExec.py");
FileWriter writer = new FileWriter(shFile);
writer.write(shebang + "\n");
writer.write(command);
writer.close();
PrintWriter printWriter = new PrintWriter(shFile);
printWriter.println(shebang);
printWriter.println(command);
printWriter.close();
((ChannelExec) channel).setCommand(FileUtils.readFileToByteArray(shFile));