草庐IT

execute_process

全部标签

go - 如何使 template.Execute() 写入文件而不是 response.Writer?

我有下面的代码来解析模板文件并将解析后的html写入ResponseWriter:-packagemainimport("net/http""html/template")funchandler(whttp.ResponseWriter,r*http.Request){t,_:=template.ParseFiles("view.html")t.Execute(w,"HelloWorld!")}funcmain(){server:=http.Server{Addr:"127.0.0.1:8080",}http.HandleFunc("/view",handler)server.List

html - 转到调用 t.Execute 中的许多参数

我正在尝试使用从数据库表中获取的值来呈现模板。问题是当我运行程序时出现错误。我不知道我做错了什么。我开始创建一个结构:typeAppstruct{TitlestringAuthorstringDescriptionstring}我创建了一个函数来呈现模板:funcrender(whttp.ResponseWriter,tmplstring,datamap[string]interface{}){tmpl=fmt.Sprintf("templates/%s",tmpl)t,err:=template.ParseFiles(tmpl)iferr!=nil{log.Print("templa

go - [CodeEval][GO] CodeEval 错误 : Process was aborted due to timeout

我正在尝试提交我的https://www.codeeval.com/open_challenges/158/解决方案这是一个冒泡排序。我用GOlang编写代码,在我的PC上它运行良好且快速!我尝试使用go的输入代码示例,我也尝试了自己的一段代码。谁能帮帮我?我尝试以某种方式更改代码,但没有任何效果。提前致谢。 最佳答案 您的代码中可能缺少某些极端情况。参见https://getsatisfaction.com/codeeval/topics/bubble-sort-iterations-are-too-high-causing-so

go - bufio.扫描仪 : how to know if we are processing a new line or a truncated string?

我基本上需要处理从流中读取的有限缓冲区中的每个字符串行。使用bufio.Scanner,我可以逐行扫描扫描仪,但不得不使用似乎过于复杂的解决方案来检测“截断”。有更好的方法吗?非常感谢。我对任何lib或任何东西都不紧张。func(p*Parser)Read(data[]byte,tmpline*string,nint,bufSizeint){varlinestringstrdata:=string(data)scanner:=bufio.NewScanner(strings.NewReader(strdata))line=""forscanner.Scan(){ifline!=""{i

go - 以编程方式为 os.Process 编写标准输入

更新:要以编程方式“驱动”bash,您需要一个伪终端(PTY)。这就是我要找的:https://github.com/kr/ptypackagemainimport("github.com/kr/pty""io""os""os/exec")funcmain(){c:=exec.Command("grep","--color=auto","bar")f,err:=pty.Start(c)iferr!=nil{panic(err)}gofunc(){f.Write([]byte("foo\n"))f.Write([]byte("bar\n"))f.Write([]byte("baz\n")

templates - Golang setCookie() 在模板 Execute() 之后失败

作为GO的初学者,我遇到了如下情况:t,err:=template.ParseFiles("/template/login.tpl")err=t.Execute(w,nil)//ifexecutedbeforeSetCookiehttp.SetCookie(...)//failed,browserreceivednothing如果顺序改变,先到SetCookie,就可以了。我的计划是在login.tpl中ParseForm()用户名和密码,如果成功,sessionID将由发送>设置Cookie。但是现在SetCookie()必须放在login.tpl被Executed之前,这也使得Pa

process - 有没有办法可靠地列出 Go 中的子流程?

我的程序正在使用exec.Command来运行一个子进程(我无法控制),该子进程又会启动另一个子进程。问题是第二个子进程不是在第一个子进程下运行,而是在原始进程下运行,如果我需要的话,我无法明确地杀死它。我确实需要。那么,是否有一种与平台无关的方式来列出子进程,以便我可以明确地清理它? 最佳答案 与平台无关的方法是使用PIDfiles,或其他一些类似的机制。缺点是您必须让子流程应用程序(及其vendor)生成必要的信息。唯一的另一种可能性是开发您自己的多平台库,因为子流程语义和与流程相关的API因平台而异。现有的一些实用程序只是获取

templates - tmpl.Execute 和子文件 golang

我需要帮助。我需要在子文件("article.html",我的文本中的示例)://...typePagestruct{Teststring}typeNewsstruct{PageTitlestring}funcmain(){t,_:=template.ParseFiles(filepath+"core.tmpl",filepath+"article.tmpl")p:=&News{Title:"TITLE",Page:Page{Test:"TITLE",},}t.Execute(wr,p)}core.tmpl中的代码:{{template"article"}}article.tmpl中的

java - 如何触发 java 应用程序(来自 Google GO/golang sub_process 的 java -jar <app name>

我正在尝试将java命令行应用程序作为golang的子进程触发。由于某种原因它失败了,实际上当我从GO启动它时我没有得到javaAPP界面。它等待几秒钟并以错误代码“无法连接...”终止这是我尝试使用的代码:packagemainimport("fmt""os/exec")funcmain(){start_java_app_test()}funcstart_java_app_test(){cmd_prep:="java-Xmx2g-jartest_app.jar"cmd_output,err:=exec.Command("bash","-c",cmd_prep).Output()ife

macos - 更新到 macOS beta 4 后,go test -cover 抛出 "fatal error: unexpected signal during runtime execution"

Gobuild和gotest仍然有效。在更新到macOSbeta之前,我使用测试覆盖工具没有遇到任何问题。“去测试”工作正常;但是,所有覆盖率测试命令都抛出此错误(gotest-coverprofile=coverage.out抛出相同的问题)。如果有人知道如何解决这个问题,我将不胜感激!$gotest-covergobuildgithub.com/hunteramericano/ErrorQuiver:/usr/local/Cellar/go/1.6.3/libexec/pkg/tool/darwin_amd64/cover:signal:fatalerror:unexpecteds