0

在 Windows 中自动执行 diskpart 命令需要指向一个 .txt 文件,该文件包含您要执行的命令序列。我正在编写一个需要使用此自动化功能的 C 程序。我想让它完全独立于工作目录运行。我该怎么做?

4

1 回答 1

0

Either use a fully qualified name for the file, or, with a bit more work, pass the commands from the C program to diskpart through an anonymous pipe using popen.

Example added:

#include <stdio.h>

int main ( int argc, char *argv[] )
{
    char buffer[MAXBUF];
    FILE *fp = popen("gzip -dc data.gz","r");

    while (fgets(buffer,MAXBUF,fp)) {
        /* Process line of data, here just print it out… */
        fputs(buffer,stdout);
    }

    printf ("Command exit status %d\n", pclose(fp));
}
于 2012-05-29T16:50:25.613 回答