0

Is there any way i can call a batch-file from within my F# program? My batch file is called eso.bat, and is to download the html content of a website. The file works, but it would be nice if it could be done automatically by the program itself.

CKMA
  • 49
  • 1
  • 4
  • 6
    You call it the same way you would in any .NET language, throug the [Process](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process?view=netframework-4.7.2) class. Why use a batch file to download anything though? Why not use *F#* to do that? Check [How to consume HttpClient from F#?](https://stackoverflow.com/questions/26195133/how-to-consume-httpclient-from-f) and [Http.fs](https://github.com/haf/Http.fs) for a more F#-friendly library – Panagiotis Kanavos Jan 23 '19 at 12:40
  • Something with the IT department were I work. The firewall blocks the response from the server, so I always get a connect failure. But for some reason it works with batch files. – CKMA Jan 24 '19 at 12:33
  • Batch files, or rather, the commands they execute, are affected by firewalls too. You should probably check what that batch does. Perhaps it uses a specific proxy or credentials – Panagiotis Kanavos Jan 24 '19 at 12:33
  • Would you be able to explain how i do that? I am only a student assistant on a minor project, and i am only done with first semester of computer science, so i am by no means a master. – CKMA Jan 30 '19 at 09:48

1 Answers1

2

The simple way is:

open System.Diagnostics
Process.Start "..\eso.bat"

if you need to pass parameteres or specify the starting directory then:

open System.Diagnostics
let procStart   = ProcessStartInfo("eso.bat", "params", WorkingDirectory = "..")
let proc        = new Process(StartInfo = procStart)
proc.Start()
AMieres
  • 4,944
  • 1
  • 14
  • 19