InCLanguageAvailableSystemThe function calls the system command to obtain the output.ProgramThe output is saved to the file for use, but it is not very convenient to use. Here I will introduce how to usePythonAndGoLanguage implementation, you can directly Save the output of other programs as variables for the program to use.
The following example usesLsName, installation requiredMingwAndC: \ mingw \ msys \ 1.0 \ bin"Add environment variables.
I. UsePythonCall other programs and get the output
ExampleCode:
ImportOS
Var = OS. popen ('Ls-l'). Read ()
PrintVaR
Running Effect (take my machine as an example ):
II,UseGoLanguage calls to other programsAnd get the output.
GoCode:
Package main
Import (
"EXEC" // "OS/exec" in go1
"FMT"
)
Func main (){
CMD: = Exec.Command("Ls", "-l ")
Buf, err: =CMD. Output ()
FMT. printf ("% s \ n % s", Buf, err)
}
The running effect is as follows:
Python and go are easy to use. If you like it, select it. Okay, that's all. I hope it will help you.