Running batch file with parameters in Python OR F #

I was looking for a site, but I did not see anything suitable for what I was looking for. I created a standalone application that uses the created web service. To start the client, I use:

C:/scriptsdirecotry> "run-client.bat" param1 param2 param3 param4

How will I code this in Python or F #. It sounds like it should be pretty simple, but I haven't seen anything on the Internet, which is exactly what I'm looking for.

+3
source share
3 answers

Python is similar.

import os
os.system("run-client.bat param1 param2")

If you require asynchronous behavior or redirected standard threads.

from subprocess import *
p = Popen(['run-client.bat', param1, param2], stdout=PIPE, stderr=PIPE)
output, errors = p.communicate()
p.wait() # wait for process to terminate
+7
source

F # Process System.Diagnostics. :

open System.Diagnostics
Process.Start("run-client.bat", "param1 param2")

, , ProcessStartInfo ( ).

+8

fsi.exe F # script (.fsx). "Script.fsx"

#light

printfn "You used following arguments: "
for arg in fsi.CommandLineArgs do
  printfn "\t%s" arg

printfn "Done!"

:

fsi --exec .\Script.fsx hello world

FSharp

You used following arguments:
        .\Script.fsx
        hello
        world
Done!

fsi.exe msdn: http://msdn.microsoft.com/en-us/library/dd233172.aspx

+2

Source: https://habr.com/ru/post/1747259/


All Articles