Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to execute an exe with variable value for path and arguments

Tags:

powershell

I'm trying to execute in my powershell script the command below :

D:\Apps\Documentum\product\7.3\bin\idql.exe -udmadmin -pPassword dctm04 -RC:\temp\documentum\session_list.txt -w20 > C:\temp\documentum\session_logstash.txt

In my powershell script I do that:

$DOCBASE="dctm04"
$USER_DOCBASE="dmadmin"
$USER_PWD="Password01"
$IDQL_PATH="D:\Apps\Documentum\product\7.3\bin"
$QRY_SESSIONS="C:\temp\documentum\session_list.txt"
$QRY_LOG_SESSIONS="C:\temp\documentum\session_logstash.txt"

$IDQL_PATH\idql.exe -u$USER_DOCBASE -p$USER_PWD $DOCBASE -R$QRY_SESSIONS -w20 > $QRY_LOG_SESSIONS

But it doesn't work properly, I receive the error below :

At C:\temp\documentum\Generate.ps1:49 char:13
+   $IDQL_PATH\idql.exe -u$USER_DOCBASE -p$USER_PWD $DOCBASE -R$QRY_SESSIONS -w20  ...
+             ~~~~~~~~~
Unexpected token '\idql.exe' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : UnexpectedToken

I think, i don't use variable properly on my command.

Please note my powershell version is :

PS C:\temp\documentum> $PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
4      0      -1     -1

could you give me the solution in order to solve my problem

like image 663
Loudone Avatar asked Feb 04 '23 22:02

Loudone


1 Answers

The reason is that combining a string to executable name makes no sense to Powershell's parsing rules. Use the call operator & or Invoke-Item. Like so,

$ssms="C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio"
PS C:\> $ssms\ssms.exe
At line:1 char:6
+ $ssms\ssms.exe
+      ~~~~~~~~~
Unexpected token '\ssms.exe' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken

C:\>& $ssms\ssms.exe
# Launches SSMS succesfully

C:\>Invoke-Item $ssms\ssms.exe
# Launches SSMS succesfully

There's nice a document about running executables.

like image 160
vonPryz Avatar answered May 12 '23 09:05

vonPryz