2016-09-25 07:24
浏览 1.3k

如何在Intellij IDEA参数中使用通配符

I use try add arguments in run configuration.

I add master sequential pg-*.txt. But when I start running. the error come out.

/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

But I use the command in terminal is 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

I think the problem is the Wildcard.So how to use Wildcard in Intellij IDEA arguments?

图片转代码服务由CSDN问答提供 功能建议

我在运行配置中使用try add参数。

我添加主顺序pg-*。txt 。 但是当我开始跑步时。 错误会出来。

  / usr / local / go / bin / go运行/home/asus/dev/6.824/src/main/wc.go master顺序pg-  * .txt 
master:启动Map / Reduce任务wcseq 


 〜/ dev / 6.824 / src / main $ / usr / local / go / bin / go run /home/asus/dev/6.824/src/  main / wc.go主序列pg-*。txt 
master:启动Map / Reduce任务wcseq 
合并:读取mrtmp.wcseq  -res-2 
master:Map / Reduce任务已完成

我认为问题在于通配符。那么如何在Intellij IDEA参数中使用通配符?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doutangqi4444 2016-09-25 19:43

    The string pg-*.txt is referred to as a glob pattern. In the latter example you are asking your shell to execute a given command which includes your glob pattern. The shell evaluates the glob pattern as a pre-processing step. The Go program then receives a list of files that have been matched by the pattern.

    You will have to update your IntelliJ settings to run the program within a shell as described in In JetBrains IDEs (e.g. CLion, IntelliJ), external tools cannot use globbing patterns Stack Overflow question. By evaluating the initial go run command within a shell process your program will receive the arguments as expected.

    An alternative solution is to treat all your arguments as glob patterns and utilize the filepath.Glob(pattern string) (matches []string, err error) function to manually expand on the provided argument. This strategy requires a little more preprocessing from your program but is more tolerant to the runtime environment. You can see an example of this kind of expansion in this Go Playground Example.

    点赞 打赏 评论

相关推荐 更多相似问题