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

标签 intellij-idea go

我尝试在运行配置中添加参数。

我添加了 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 参数中使用通配符呢?

最佳答案

字符串 pg-*.txt 被称为 glob图案。在后一个示例中,您要求 shell 执行包含 glob 模式的给定命令。 shell 将 glob 模式评估为预处理步骤。然后,Go 程序会收到与该模式匹配的文件列表。

您必须更新您的 IntelliJ 设置才能在 shell 中运行该程序,如 In JetBrains IDEs (e.g. CLion, IntelliJ), external tools cannot use globbing patterns 中所述。堆栈溢出问题。通过在 shell 进程中评估初始 go run 命令,您的程序将按预期接收参数。

另一种解决方案是将所有参数视为 glob 模式并利用 filepath.Glob(pattern string) (matches []string, err error)函数手动扩展提供的参数。此策略需要您的程序进行更多的预处理,但对运行时环境的容忍度更高。您可以在 Go Playground Example 中看到这种扩展的示例.

关于intellij-idea - 如何在 Intellij IDEA 参数中使用通配符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39684417/

相关文章:

go - 如何使用两个客户端。使用golang

arrays - 在Go中,如何解码包含结构数组的字符串

maven - 如何让 Maven 下载特定依赖项的源代码和 javadoc?

intellij-idea - 如何在 Intellij IDEA 的实时模板中使用变量值?

go - 解析 RSA 公钥时出错

pointers - 返回类型与 struct golang 相同

javascript - 如何增加 Webstorm 调试器中显示的帧数?

intellij-idea - 是否可以列出所有在 IntelliJ IDEA 中有本地更改的文件(在 "Changes" View 之外)

Mac 上找不到 Android aapt

go - 如何在 golang 的日期上加 1 秒?