Execute-Process and .bat with args best pratices

Hey all,

Today I need to include in a PSADT deployment a .bat script with parameters… The bellow commandline works in a cmd:

call C:\TCINSTALL\Teamcenter\Tc14.2.0.0_wntx64\wntx64\tem.bat -jre "C:\BCTSI\custom\java\jdk11" -s "C:\Users\Test\Desktop\1 Script\Files\silent.xml"

But I can’t find the right format with PSADT. Maybe I need to add “” for to the java path? Do you see any wrong things here? I don’t have errors in logs but just nothing running…

Execute-Process -Path 'C:\Windows\System32\cmd.exe' -Parameters "C:\TCINSTALL\Teamcenter\Tc14.2.0.0_wntx64\wntx64\tem.bat -jre $jrefolder -s $dirFiles\silent.xml"

I would try escaping the double-quotes with a back-tick like this:

Execute-Process -Path 'C:\Windows\System32\cmd.exe' -Parameters "C:\TCINSTALL\Teamcenter\Tc14.2.0.0_wntx64\wntx64\tem.bat -jre `"$jrefolder`" -s `"$dirFiles\silent.xml`""

Thanks for the idea, we must be getting close to the goal, because the command in the log file looks almost like the cmd command but still nothing happens.

Alright I found it, I missed /c “Carries out the command specified by string and then stops.”, source: cmd | Microsoft Learn

Execute-Process -Path "C:\Windows\System32\cmd.exe" -Parameters "/c C:\TCINSTALL\Teamcenter\Tc14.2.0.0_wntx64\wntx64\tem.bat -jre `"$jrefolder`" -s `"$dirFiles\silent.xml`""

So basically to run a bat script inside PSADT:

Execute-Process -Path "$envSystem32Directory\cmd.exe" -Parameters "/c $dirFiles\BATSCRIPT.bat -otherparams"

In case of paramters with path must be inside quotes, add `" and good :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.