2016-09-25 17 views
1

我在運行配置中使用try add參數。如何在Intellij IDEA參數中使用通配符

我加master sequential pg-*.txt。但是當我開始跑步。錯誤出來了。

/usr/local/go/bin/go run /home/asus/dev/6.824/src/main/wc.go master sequential pg-*.txt 
master: Starting Map/Reduce task wcseq 
panic: open pg-*.txt: no such file or directory 

但我在終端中使用的命令是OK的。

~/dev/6.824/src/main$ /usr/local/go/bin/go run /home/asus/dev/6.824/src/main/wc.go master sequential pg-*.txt 
master: Starting Map/Reduce task wcseq 
Merge: read mrtmp.wcseq-res-0 
Merge: read mrtmp.wcseq-res-1 
Merge: read mrtmp.wcseq-res-2 
master: Map/Reduce task completed 

我認爲問題是通配符。所以如何在Intellij IDEA參數中使用通配符?

回答

1

字符串pg-*.txt被稱爲glob模式。在後面的例子中,你要求你的shell執行一個包含你的glob模式的給定命令。 shell會將glob模式評估爲預處理步驟。 Go程序然後接收已被模式匹配的文件的列表。

您必須更新IntelliJ設置才能在shell中運行該程序,如In JetBrains IDEs (e.g. CLion, IntelliJ), external tools cannot use globbing patterns Stack Overflow問題中所述。通過評估shell進程中的初始運行命令,程序將按預期接收參數。

另一種解決方案是將所有參數視爲全局模式,並利用filepath.Glob(pattern string) (matches []string, err error)函數手動擴展所提供的參數。這種策略需要從程序中進行更多的預處理,但對運行時環境更爲寬容。您可以在此Go Playground Example中看到這種擴展的示例。