Executing a .sh file from Object Script
Hi Everyone,
I am a very new to IRIS Object Script Development. There is a usecase where I have to execute a .sh file from the object script. I am looking for examples for that, but what I find is the ways to execute the shell commands. Can you please point me to some examples executing a .sh file. Thanks in Advance
Comments
Hello, Sathish, I recently published test-data app that utilizes a shell script to create a test file:
facture.cls defines the parameters for the RunScript classmethod.
| ClassMethod DefineProductScript( | |
| pName As %String = "Demo2", | |
| pDebug As %Integer = 0) As %Status | |
| { | |
| Set pQuery = "SELECT ID from dc_iris.product WHERE Name = '?'" | |
| Set pQuery = $Replace(pQuery,"?",pName) | |
| Write:pDebug pQuery,! | |
| Set tSC = ##class(dc.iris.util).ExecuteQueryOneValue(pQuery,.oProduct) | |
| Write:pDebug tSC,! | |
| Set oProduct = ##class(dc.iris.product).%OpenId(oProduct) | |
| If ($IsObject(oProduct) = 0) Set oProduct = ##class(dc.iris.product).%New() | |
| Do:pDebug $System.OBJ.Dump(oProduct) | |
| Set oProduct.ClassName = "dc.iris.product" | |
| Set oProduct.MethodName = "RunScript" | |
| Set oProduct.RunCmd = "/opt/irisbuild/demo.sh" | |
| Set pRandom = "random" | |
| Set pOutput = "/opt/transform/practice/" | |
| Set pTemplate = "/usr/irissys/mgr/data/" | |
| Set oProduct.RunParam1 = "$Qty" | |
| Set oProduct.RunParam2 = pRandom | |
| Set oProduct.RunParam3 = pOutput | |
| Set oProduct.RunParam4 = pTemplate | |
| Set oProduct.Name = pName | |
| //Set oProduct.TargetPath = "/opt/transform/practice/" | |
| Set tSC = oProduct.%Save() | |
| Quit tSC | |
| } |
| ClassMethod RunScript( | |
| pProduct, | |
| pQuantity) As %Status | |
| { | |
| Set tSC = $$$OK | |
| Set oProduct = $Get(pProduct) | |
| If ($IsObject(oProduct) = 0) { | |
| Set oProduct = ##class(dc.iris.product).%OpenId(oProduct) | |
| } | |
| If ($IsObject(oProduct) = 0) { | |
| Set tSC = $$$ERROR($$$GeneralError,"No product defined") | |
| Quit tSC | |
| } | |
| Set pCmd = oProduct.RunCmd | |
| Set pNumberOfFiles = $Get(pQuantity,1) | |
| Set args=4 | |
| Set args(1) = oProduct.RunParam1 | |
| Set args(2) = oProduct.RunParam2 | |
| Set args(3) = oProduct.RunParam3 | |
| Set args(4) = oProduct.RunParam4 | |
| For ii = 1:1:args { | |
| If (args(ii) = "$Qty") Set args(ii) = pNumberOfFiles | |
| } | |
| Set tReturn = $ZF(-100,"/SHELL",pCmd,.args) | |
| Quit tSC | |
|
} |
Hi Wilms, Thanks for sharing the details.! Let me run this and let me get back.
@Oliver Wilms Is there any difference in running the command $ZF in linux installed IRIS? Because we have our IRIS installed in a linux server, and even the $ZF command seems to be returning 1, I don't see the expected output.
Some details on what I am trying to do with the script is, hit an external endpoint, which will download a .zip file and the script will extract it and put in a destination folder.
Hello, can you verify that the script is executed? Are permissions properly set? Can you try with a different more simple script such as echo "some message" > someFile? I also use IRIS (containers) on Linux.
Did you check the use of CPIPE ?
Open Exchange Execute Server Commands from Caché / Ensemble / IRIS
No @Robert Cemper Wilms example worked well.
@Oliver Wilms you are correct there was some permission issues at the folder, fixing that it worked wonderfully :). Thanks a lot!