CaptnCodr / Fli

Execute CLI commands from your F# code in F# style!
MIT License
153 stars 5 forks source link

How would I open an HTML page in the default browser? #55

Closed mrboring closed 9 months ago

mrboring commented 9 months ago

Hi I'm trying to open an HTML file in the default browser.

cli {
    Exec @"<full path to HTML file>"
}
|> Command.execute

The above gives me the following exception:

System.ComponentModel.Win32Exception (193): An error occurred trying to start process 'C:\Data\FSharp\Projects\AudioUtilities\DO NOT COMMIT\Script Files\Find Audio Issues\Untitled-1.html' with working directory 'C:\Data\FSharp\Projects\AudioUtilities'. The specified executable is not a valid application for this OS platform.
   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
   at Fli.Command.startProcess(FSharpFunc`2 inputFunc, FSharpFunc`2 outputFunc, ProcessStartInfo psi) in C:\Users\const\github\repos\Fli\src\Fli\Command.fs:line 87
   at Fli.Command.Command.execute(ExecContext context) in C:\Users\const\github\repos\Fli\src\Fli\Command.fs:line 223
   at <StartupCode$FSI_0024>.$FSI_0024.main@()
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)        
Stopped due to error

I searched for The specified executable is not a valid application for this OS platform and found the following (old ) Stack Overflow page:

.Net Core 2.0 Process.Start throws "The specified executable is not a valid application for this OS platform"

It suggests setting UseShellExecute = true. How would I do this with Fli, or is there a better way?

Thanks.

CaptnCodr commented 9 months ago

Hi @mrboring, thanks for opening an issue about Fli.

It is at present not possible to open a file with the default/assigned application.

Currently you need to specify the application with the file:

cli {
    Exec @"path\where\application\is\chrome.exe"
    Arguments @"this\is\test.html"
}
|> Command.execute

I write it on the todo-list to just have:

cli {
    Exec @"this\is\test.html"
}
|> Command.execute

for opening in default application.

CaptnCodr commented 9 months ago

@mrboring This change is now in v1.10.0 available. Thank you for your input and have fun. 🙂

mrboring commented 9 months ago

@CaptnCodr Thanks for the quick update. Tested and working in my scenario.