1

This is a new question stemming from a previous post at :

Run Powershell script from inside other Powershell script with dynamic redirection to file

I am running:

$logStreams = "2>&1>"

$command = '"C:\myscript.ps1" $_logStreams "C:\outputlog.txt"'

iex "& $command"

I observed that calling my script with iex "& $ command" is different than running it using Powershel -File "C:\myscript.ps1".

Myscript.ps1 calls a function Download (with some params) which creates and fills up a file $File1 then a second file $File2 (also it generates a third file from the previous two ones).

Then, in the next line in myscript.ps1 after calling Download(), I call another function Cleanup($File1, $File2) which deletes $File1 and $File2. All this works flawlessly with Powershell -File "C:\myscript.ps1" however when using iex "& $command" as above the Cleanup function complains it cannot bind $File1 and $File2 because they are null !

It is like iex executed the Download and Cleanup functions in parallel (call Download, do not wait for it to complete -> immediately call Cleanup). Is that an expected behavior of iex or am I missing something basic here ?

Community
  • 1
  • 1
Kano Chodapra
  • 103
  • 1
  • 4

0 Answers0