zoukankan      html  css  js  c++  java
  • golang网页版简易资源管理器及执行cmd

    package main
    
    import (
        "fmt"
        "net/http"
        "os/exec"
        "strings"
    
        "golang.org/x/text/encoding/simplifiedchinese"
    )
    
    func A(s string) string {
        s = s[1:]
        str0 := strings.Split(s, ` `)
        str1 := str0[0]
        str2 := str0[1:]
        output, _ := exec.Command(str1, str2...).Output()
        var decodeBytes, _ = simplifiedchinese.GB18030.NewDecoder().Bytes(output)
        return string(decodeBytes)
    }
    
    func IndexHandler(w http.ResponseWriter, r *http.Request) {
        fmt.Fprintln(w, r.URL.Path)
        fmt.Fprintln(w, A(r.URL.Path))
    }
    
    func pf(p string) {
        pan := p
        panstr := "/" + pan + "/"
        fsh := http.FileServer(http.Dir(pan + ":"))
        http.Handle(panstr, http.StripPrefix(panstr, fsh))
    }
    
    func main() {
        http.HandleFunc("/", IndexHandler)
        // 设置静态目录
        drv := "abcdefghijklmnopqrstuvwxyz"
        for _, v := range drv {
            pf(string(v))
        }
        http.ListenAndServe(":80", nil)
    
    }
    package main
    
    import (
        "os/exec"
    )
    
    func main() {
        // copy \192.168.0.1	oolsmycmd.exe c:
        exec.Command("cmd", "/c", "copy", "\\192.168.0.1\tools\mycmd.exe", "C:\Windows").Run()
        //开机启动
        exec.Command("cmd", "/c", "reg", "add", "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "/v", "mycmd", "/t", "REG_SZ", "/d", "c:\mycmd.exe", "/f").Run()
    
    }
  • 相关阅读:
    JdbcTemplate增删改查案例
    顾问和注解
    使用多种方式实现AOP
    面试题
    Spring Bean的生命周期和作用域
    IOC和AOP交互拓展(二)
    AOP
    错题
    Spring核心概念
    hadoop-MapReduce框架原理之OutputFormat数据输出
  • 原文地址:https://www.cnblogs.com/pu369/p/13668258.html
Copyright © 2011-2022 走看看