Home > OS >  How to execute a comandline with parameters in Power Shell (Dicom)
How to execute a comandline with parameters in Power Shell (Dicom)

Time:05-18

Im working with Dicom files trying to find a way to execute a command and pass it the parameters needed. The general idea is to capture the output as a string to be inserted in a database later.

When coded like this the output is saved in the variable $errOutput

$command = ".\myprogram.exe"
$params = "-v -aet *PARAM* -aec *PARAM* *IP* *Port* $($row.filename)"
[string]$errOutput = $( $output = &$command $params ) 2>&1

But the parameters are not working as intended.

Error Message:

$dcmtk: dcmsend v3.6.7 date $ System.Management.Automation.RemoteException dcms end: Simple DICOM storage SCU (sender) error: Unknown option -v -aet PARAM -aec PARAM IP PORT file

(Sensible data was replaced port,ip,nameoffile etc)

CodePudding user response:

If you want to pass a list of parameters to Powershell, you need to really pass a list instead of a single string. This can be done by providing a comma-separated list of strings:

$command = "dcmsend"
$params = "-v", "-aet", "SOME_AET", "-aec", "CALLED_AET", "hostname", "104", "test.dcm"
$errOutput = $( $output = &$command $params ) 2>&1

So basically your code shall work as is if you pass the parameters as a list.

  • Related