如何在Intellij IDEA参数中使用通配符 [英] how to use Wildcard in Intellij IDEA arguments

查看:307
本文介绍了如何在Intellij IDEA参数中使用通配符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I use try add arguments in run configuration.

我添加 master顺序pg-*.txt .但是当我开始跑步时.错误出来了.

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

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

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

推荐答案

字符串 pg-*.txt 被称为

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.

您将必须更新IntelliJ设置,才能在

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.

另一种解决方案是将所有参数视为全局模式,并利用 filepath.Glob(模式字符串)(匹配[] string,错误错误) 函数,以在提供的参数上手动扩展.此策略需要对程序进行更多的预处理,但对运行时环境的容忍度更高.您可以在> 转到游乐场示例"中看到这种扩展的示例..

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.

这篇关于如何在Intellij IDEA参数中使用通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆