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

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

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

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题