0

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

2
  • How exactly does it "not work"? Commented Sep 9, 2013 at 21:03
  • It does not do nothing at all. If I run that command from bash it runs ok. But If I run it within that, it tells "Bad usage", and that is because the script is not replace $actDate for 2013-09-09... Still, I found a way to make it work. Commented Sep 9, 2013 at 21:31

2 Answers 2

1

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" /?'}
Sign up to request clarification or add additional context in comments.

1 Comment

I tried that, if I make -command { cmd.exe /c "c:\$actDate" } the ouptut in the console after Get-Job is cmd.exe /c "C:\$actDa.. instead of C:\2013-09-09...
0

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.

1 Comment

The powershell attribute $actDate was out of context from the scriptblock -command { } the solution you said that works puts the variable in context...At least so i think :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.