1

I'm trying to start a job that creates a file. But it doesn't.

here's the very simple code:

start-job -ScriptBlock { "hi" | set-content "hi.txt" }

The file "hi.txt" never gets created.

Why not?

4

1 回答 1

4

It is most likely creating the file, just not where you expect because you used a relative path. Try executing this to see where the file is going:

Start-Job {$pwd} | Receive-Job -Wait

Better yet, use an absolute path:

Start-Job { 'hi' > c:\hi.txt }

Or pass in the desired path:

Start-Job {param($path) 'hi' > "$path\hi.txt"} -arg $pwd
于 2013-10-23T03:26:54.767 回答