簡體   English   中英

在 rust (vim) 中運行命令

[英]Running commands in rust (vim)

std::process::Command::new("/usr/bin/sh")
    .arg("-c")
    .arg("vim")
    .arg("file")
    .spawn()
    .expect("Error: Failed to run editor");

當我運行此代碼時,運行了一個 vim 進程,編輯文件,盡管它沒有在終端中打開(不確定確切的術語)我/是否有可能在終端中實際打開 vim

當我運行你的代碼時, vim確實在終端中打開,但我的 shell 也在同一個終端中運行,vim 和 shell 都為顯示而戰,它們都接收我輸入的任何鍵。 如果這也是您看到的問題,您需要等待子進程:

std::process::Command::new("/usr/bin/sh")
    .arg("-c")
    .arg("vim")
    .arg("file")
    .spawn()
    .expect("Error: Failed to run editor")
    .wait()
    .expect("Error: Editor returned a non-zero status");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM