Skip to content

Command.execute fails if Input contains any curly braces #85

Description

@svenvanheugten

Describe the bug
Command.execute fails if Input contains any curly braces.

Repro steps
Run the following F# script file:

#r "nuget: Fli,1.1000.0"

open Fli

cli {
    Exec "cat"
    Input "{"
}
|> Command.execute

Expected behavior
cat runs successfully.

Errors or actual behavior

System.FormatException: Input string was not in a correct format. Failure to parse near offset 1. Format item ends prematurely.
   at System.Text.ValueStringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ReadOnlySpan`1 args)
   at System.IO.StreamWriter.WriteFormatHelper(String format, ReadOnlySpan`1 args, Boolean appendNewLine)
   at System.IO.StreamWriter.WriteLine(String format, Object arg0)
   at Fli.Command.writeInput$cont@177(FSharpOption`1 input, FSharpOption`1 encoding, Process p, Unit unitVar) in D:\github\repos\Fli\src\Fli\Command.fs:line 179
   at Fli.Command.writeInput(FSharpOption`1 input, FSharpOption`1 encoding, Process p) in D:\github\repos\Fli\src\Fli\Command.fs:line 175
   at Fli.Command.execute@297-2.Invoke(Process p)
   at Fli.Command.startProcess(FSharpFunc`2 inputFunc, FSharpFunc`2 outputFunc, Boolean isStreaming, ProcessStartInfo psi) in D:\github\repos\Fli\src\Fli\Command.fs:line 114
   at Fli.Command.Command.execute(ExecContext context) in D:\github\repos\Fli\src\Fli\Command.fs:line 293
   at <StartupCode$FSI_0002>.$FSI_0002.main@() in /home/sven/Repos/Fli-experiment/input.fsx:line 7
   at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

Related information:

  • OS: Linux
  • .NET version: 10.0.203

Cause
This seems to be caused by the fact that the following call uses the void WriteLine(string format, object arg0) overload, which means that inputText is treated as a format string (and that encoding doesn't actually do anything):

sw.WriteLine(inputText, encoding)

Work-around
The asynchronous version doesn't have the same problem, so switching to Command.executeAsync >> Async.RunSynchronously is a functioning work-around.

Activity

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions