我试图找出如何从Go程序中启动外部编辑器,等待用户关闭编辑器,然后继续执行该程序.根据这个 SO答案,我目前有这个代码:
package main
import (
"log"
"os"
"os/exec"
)
func main() {
fpath := os.TempDir() + "/thetemporaryfile.txt"
f, err := os.Create(fpath)
if err != nil {
log.Printf("1")
log.Fatal(err)
}
f.Close()
cmd := exec.Command("vim", fpath)
err = cmd.Start()
if err != nil {
log.Printf("2")
log.Fatal(err)
}
err = cmd.Wait()
if err != nil {
log.Printf("Error while editing. Error: %v\n", err)
} else {
log.Printf("Successfully edited.")
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行程序时,我得到了这个:
chris@DPC3:~/code/go/src/launcheditor$ go run launcheditor.go
2012/08/23 10:50:37 Error while editing. Error: exit …Run Code Online (Sandbox Code Playgroud) 我使用QT Designer和Pyside制作了一个GUI程序,它完全有效.唯一的问题是每当我运行它时,我会在后台获得一个cmd.exe窗口.这很烦人.有没有什么办法解决这一问题?
我已经使用Python了一段时间,但在今天之前我从来没有真正做过任何并发.我偶然发现了这篇博文,并决定制作一个类似(但更简单)的例子:
import os
import threading
import Queue
class Worker(threading.Thread):
def __init__(self, queue, num):
threading.Thread.__init__(self)
self.queue = queue
self.num = num
def run(self):
while True:
text = self.queue.get()
#print "{} :: {}".format(self.num, text)
print "%s :: %s" % (self.num, text)
self.queue.task_done()
nonsense = ["BLUBTOR", "more nonsense", "cookies taste good", "what is?!"]
queue = Queue.Queue()
for i in xrange(4):
# Give the worker the queue and also its "number"
t = Worker(queue, i)
t.setDaemon(True)
t.start()
for gibberish in nonsense:
queue.put(gibberish) …Run Code Online (Sandbox Code Playgroud) 由于我正在学习C#,我做了一个小程序来计算X的斐波那契数量.然而,随着数字迅速变大,即使是无符号长数也不能保持数字.我该如何解决这个问题?制作我自己的超大整数数据类型?