linux - 使用 std::process::Command 时未正确传递长格式参数

标签 linux rust command-line-interface

我遇到一个问题,即长格式参数未正确传递给特定的命令行实用程序。

所有这些都有效:

Command::new("mpg321").arg("--gain 100").arg("file.mp3").spawn().unwrap()
Command::new("mpg123").arg("-h 2").arg("file.mp3").spawn().unwrap()
mpg123 --halfspeed 2 file.mp3

但是这个:

Command::new("mpg123").arg("--halfspeed 2").arg("file.mp3").spawn().unwrap()

返回:

mpg123: Unknown option "halfspeed 2"

我怀疑故障出在 mpg123 一侧,但这并不完全有意义,因为它在从命令行调用时有效。

最佳答案

--halfspeed 2 是两个参数。你应该调用 arg 两次:

Command::new("mpg123").arg("--halfspeed").arg("2").arg("file.mp3")...

或使用 .args 将所有参数一起作为数组传递:

Command::new("mpg123").args(&["--halfspeed", "2", "file.mp3"])...

关于linux - 使用 std::process::Command 时未正确传递长格式参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37443293/

相关文章:

linux - 为什么这个 cron 作业每分钟运行一次?

Rust mod 文件在同一文件夹中 vs 使用

c# - MS Blend 3&4 能否打开包含混合代码的解决方案?

windows - 从批处理脚本启动 Windows 服务并根据结果采取适当的操作

python - 在 Linux 中从 R 运行 keras 时出错

linux - 禁用回溯

python - 有没有办法直接将 python 输出发送到剪贴板?

rust - 为什么使用外部包装箱的功能需要将依赖特征纳入范围?

sorting - rust 添加.sort_by生成错误: expected struct `Vec` ,发现 `()`

java - Java 中的输入文件