dougua9165 2016-09-25 07:24
浏览 2336
已采纳

如何在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?

  • 写回答

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥200 相机拍直接转存到电脑上 立拍立穿无线局域网传
  • ¥15 (关键词-电路设计)
  • ¥15 如何解决MIPS计算是否溢出
  • ¥15 vue中我代理了iframe,iframe却走的是路由,没有显示该显示的网站,这个该如何处理
  • ¥15 操作系统相关算法中while();的含义
  • ¥15 CNVcaller安装后无法找到文件
  • ¥15 visual studio2022中文乱码无法解决
  • ¥15 关于华为5g模块mh5000-31接线问题
  • ¥15 keil L6007U报错
  • ¥15 webapi 发布到iis后无法访问