Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to redirect output from one process to another #2445

Closed
ZeekoZhu opened this issue Dec 18, 2019 · 2 comments
Closed

Unable to redirect output from one process to another #2445

ZeekoZhu opened this issue Dec 18, 2019 · 2 comments

Comments

@ZeekoZhu
Copy link

Description

Unable to redirect output from one process to another as described in Advanced usage scenarios

Repro steps

  1. Create build.fsx
#r "paket:
nuget Fake.IO.FileSystem
nuget Fake.Core.Target //"
#load ".fake/build.fsx/intellisense.fsx"
open Fake.Core
open Fake.Core.TargetOperators

Target.initEnvironment ()

Target.create "Build" (fun _ ->
    let input = StreamRef.Empty
    let p1 =
        CreateProcess.fromRawCommand "tee" []
        |> CreateProcess.withStandardInput (CreatePipe input)
        |> Proc.start
    let p2 =
        CreateProcess.fromRawCommand "echo" ["can not pipe output"]
        |> CreateProcess.withStandardOutput (UseStream (false, input.Value))
        |> Proc.run

    p1.Wait()
)

Target.create "All" ignore

"Build"
  ==> "All"

Target.runOrDefault "All"
  1. run All target
fake build

Expected behavior

Target succeed.

Actual behavior

Target failed with:

The last restore is still up to date. Nothing left to do.
run All
Building project with version: LocalBuild
Shortened DependencyGraph for Target All:
<== All
   <== Build

The running order is:
Group - 1
  - Build
Group - 2
  - All
Starting target 'Build'
> "/usr/bin/mono" --version (In: false, Out: true, Err: true)
> "tee"  (In: true, Out: false, Err: false)
Finished (Failed) 'Build' in 00:00:01.1162226

---------------------------------------------------------------------
Build Time Report
---------------------------------------------------------------------
Target     Duration
------     --------
Build      00:00:01.1121621   (Can retrieve data cell before it has been set!)
All        00:00:00           (skipped)
Total:     00:00:01.2159875
Status:    Failure
---------------------------------------------------------------------
Killing all processes that are created by FAKE and are still running.
Trying to kill process 'tee' (Id = 2703)
Script reported an error:
-> BuildFailedException: Target 'Build' failed.
   StackTrace:
        at Fake.Core.TargetModule.raiseIfError(OptionalTargetContext context) in D:\a\1\s\src\app\Fake.Core.Target\Target.fs:line 968
        at Fake.Core.TargetModule.runOrDefault(String defaultTarget) in D:\a\1\s\src\app\Fake.Core.Target\Target.fs:line 1150
        at <StartupCode$build_5196C12FDE28AC0613A3E80ADD03D9C84A5E8F47A2FC0C35838A1C506DF448C9>.$Build$fsx.main@() in /tmp/fake-create-pipe/build.fsx:line 29
-> One or more errors occurred. (Can retrieve data cell before it has been set!)
-> InvalidOperationException: Can retrieve data cell before it has been set!
   StackTrace:
        at Fake.Core.DataRef`1.get_Value() in D:\a\1\s\src\app\Fake.Core.Process\RawProc.fs:line 83
        at Build.clo@10.Invoke(TargetParameter _arg1) in /tmp/fake-create-pipe/build.fsx:line 16
        at Fake.Core.TargetModule.runSimpleInternal(TargetContext context, Target target) in D:\a\1\s\src\app\Fake.Core.Target\Target.fs:line 301
Performance:
 - Cli parsing: 231 milliseconds
 - Packages: 62 milliseconds
 - Script compiling: 3 seconds
 - Script analyzing: 218 milliseconds
 - Script running: 1 second
 - Script cleanup: 56 milliseconds
 - Runtime: 5 seconds

Known workarounds

Use shell script do redirection:

redirect.sh

echo "output" | tee

Related information

  • x86_64 Linux 4.19.88-1-MANJARO
  • dotnet-sdk 3.1.100
  • mono 6.4.0
  • FAKE 5.18.3
@matthid
Copy link
Member

matthid commented Dec 18, 2019

Thanks for reporting, yes I can reproduce. Seems like we broke this in one of the releases/bugfixes. I'll take a look and add a testcase.

@matthid
Copy link
Member

matthid commented Dec 18, 2019

You can use 5.19.0-alpha.1473 or the 5.19 release which will follow shortly.

Just make sure to use

-        |> CreateProcess.withStandardOutput (UseStream (false, input.Value))
+        |> CreateProcess.withStandardOutput (UseStream (true, input.Value))

I changed the documentation accordingly. The reason is that otherwise tee will never exit as the standard input will never be closed. You can use false to write additional stuff after echo has exited, or spawn another echo process

Again, thanks for reporting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants