Answer the question
In order to leave comments, you need to log in
golang. Windows. Why doesn't creating a folder through a new cmd window work?
Task: make a folder through a new cmd window, I know that there is a standard library for this, but the point is to understand how to work with the standard flows of a process launched in a new console window, and not in creating a folder.
Please advise what is wrong.
package main
import(
"os/exec"
"log"
)
func main(){
cmdNewWindow := exec.Command("cmd", "/C", "start cmd.exe")
pipe, err := cmdNewWindow.StdinPipe()
if err != nil {
log.Fatal("Error: ",err)
}
pipe.Write([]byte("md C:\\1"))
pipe.Close()
cmdNewWindow.Run()
}
Answer the question
In order to leave comments, you need to log in
func ExampleCmd_StdinPipe() {
cmd := exec.Command("cat")
stdin, err := cmd.StdinPipe()
if err != nil {
log.Fatal(err)
}
go func() {
defer stdin.Close()
// тута писать туда
io.WriteString(stdin, "values written to stdin are passed to cmd's standard input")
}()
out, err := cmd.CombinedOutput()
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", out)
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question