Created
June 19, 2022 05:33
-
-
Save fengyfei/d8d025f6fd22a869b7d9435d2ad690ff to your computer and use it in GitHub Desktop.
[Go] Command Input
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import( | |
"log" | |
"os/exec" | |
"os" | |
"io" | |
) | |
func main() { | |
process := exec.Command("vi", "/Users/fengyfei/Space/Github/Go/sample/a.txt") | |
process.Stdout = os.Stdout | |
stdin, err := process.StdinPipe() | |
if err != nil { | |
log.Fatal(err) | |
} | |
if err = process.Start(); err != nil { | |
log.Fatal(err) | |
} | |
io.WriteString(stdin, "i"); | |
io.WriteString(stdin, "hello"); | |
stdin.Write([]byte{27}) | |
io.WriteString(stdin, ":wq\n") | |
if err = process.Wait(); err != nil { | |
log.Fatal(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment