2016-09-25 296 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中看到这种扩展的示例。