Question
· Jun 28, 2022

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

Product version: IRIS 2022.1
Discussion (7)0
Log in or sign up to continue

Hello, Sathish, I recently published test-data app that utilizes a shell script to create a test file:

InterSystems Open Exchange
 

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
 

}

@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.