Cito
Cito

Reputation: 1709

Script not running at powershell

I have this snippet of code

$actDate=Get-Date -Format 'yyyy-MM-dd'
Start-job -name "FMLE" -command { cmd.exe /c 'c:\Program Files (x86)\Adobe\Flash Media Live Encoder 3.2\FMLEcmd.exe' /p C:\tasks\testing_2\testing 2_$actDate.xml /ap username:password /ab username:password /l C:\Users\acruz\AppData\Local\Temp\temp.log }

I know for sure, that the var $actDate is not being replaced at the line, how shuld I do that?

My two questions are: how to replace the $actDate for its value and how to save the result of the job to one log

Thanks for your help

EDIT

This does not works either:

$actDate = (Get-Date -Format 'yyyy-MM-dd')
$Args = ("/p C:\tasks\testing_2\testing 2_$actDate.xml","/ap username:password", "/ab uysername:password", "/l C:\Users\acruz\AppData\Local\Temp\temp.log")
$Args

$j = Start-job -name "FMLE" -ScriptBlock { & 'c:\Program Files (x86)\Adobe\Flash Media Live Encoder 3.2\FMLEcmd.exe' @args } -ArgumentList $args

Get-Job $j.Id
Receive-Job -Job $j | Out-File 'C:\Users\acruz\AppData\Local\Temp\temp.log' -encoding ASCII -append -force 

Although $Args has the right information...

Upvotes: 0

Views: 161

Answers (2)

Cito
Cito

Reputation: 1709

I was able to make it work by doing it like this:

Start-job -Verbose -ScriptBlock {
    $actDate = Get-Date -Format yyyy-MM-dd
    cd "c:\Program Files (x86)\Adobe\Flash Media Live Encoder 3.2\"
    .\FMLEcmd.exe /p "C:\site.com.mx\tasks\test_23445678\test 23445678_$actDate.xml" /ap user:password /ab user:password /l C:\site.com.mx\task.log
}

By doing it with -command it does not work, cause it does not replace the variable at all. Also, if I do it with -ArgumentList either was replacing the variable $actDate, so I though that may be by adding the whole script within the block it was work... and indeed, it did it...

So I don't know why it does not works, but this is a fix for me.

Upvotes: 0

Mitul
Mitul

Reputation: 9854

For your first question, you need to include the path using double quotes. A suggestion if you can then remove the space in the testing 2

"C:\tasks\testing_2\testing2_$actDate.xml"

To log result of the job use Receive-Job cmdlet.

One more try:
Try to put all paths in double quotes and then surround everything with a single quote after the cmd.exe /c part as shown below. Try to achieve something simpler with a simple task and then try to add complexity

$job = Start-Job -name "Hel" -Command { cmd.exe /c '"C:\Program Files (x86)\Mozilla Firefox\firefox.exe" /?'}

Upvotes: 1

Related Questions