From 4bfcf116195768516bab13bd182f0b1dcbce582b Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Sun, 16 Feb 2025 21:38:31 +0800 Subject: [PATCH] =?UTF-8?q?spawm=E6=94=AF=E6=8C=81~?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- maomao.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/maomao.c b/maomao.c index 1c190db7..6821b191 100644 --- a/maomao.c +++ b/maomao.c @@ -3,6 +3,7 @@ */ #include #include +#include #include #include #include @@ -4735,7 +4736,6 @@ void sigchld(int unused) { } void spawn(const Arg *arg) { - if (fork() == 0) { dup2(STDERR_FILENO, STDOUT_FILENO); setsid(); @@ -4745,7 +4745,13 @@ void spawn(const Arg *arg) { int argc = 0; char *token = strtok((char *)arg->v, " "); while (token != NULL && argc < 63) { - argv[argc++] = token; + // 扩展 ~ 为家目录路径 + wordexp_t p; + if (wordexp(token, &p, 0) == 0) { + argv[argc++] = p.we_wordv[0]; + } else { + argv[argc++] = token; // 如果扩展失败,使用原始 token + } token = strtok(NULL, " "); } argv[argc] = NULL; // execvp 需要以 NULL 结尾的数组