1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
package main
import (
"fmt"
"io/ioutil"
"log"
_ "os"
"os/exec"
)
func main(){
//使用ioutil读取目录
fileInfoList ,err:=ioutil.ReadDir("D:\\go-work\\src\\hugo_hk_blog\\content\\post")
if err!=nil{
log.Fatal(err)
}
for i:=range fileInfoList{
fmt.Printf("%-2d--%s\n",i,fileInfoList[i].Name())
}
//读取输入
num:=0
name:="未命名"
fmt.Scanln(&num,&name)
nameFile:="post/"+fileInfoList[num].Name()+"/"+name+".md"
//执行shell命令
cmd:=exec.Command("hugo","new",nameFile)
err1:=cmd.Run()
if err1!=nil{
fmt.Println(err1)
}
nameFile2:="content/"+nameFile
cmd2:=exec.Command("cmd","/c","start",nameFile2)
fmt.Println("test")
err2:=cmd2.Run()
if err2!=nil{
fmt.Println(err2)
}
}
|