C-在Windows中使用exec() [英] C- Using exec() in windows

查看:89
本文介绍了C-在Windows中使用exec()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到许多针对unix系统的结果.我正在使用cygwin,所以我正在使用 unistd.h 库.我正在尝试运行此命令,但无法运行.我在这里可能想念什么?

I've seen many many results for unix systems. I am using cygwin so I am using unistd.h library. I am trying to run this command but It does not run. What could I be missing here?

execl("C:\\ WINDOWS \\ SYSTEM32 \\ CMD.EXE","/c echo foo> C:\\ Users \\ Sarp \\ Desktop \\ foo.txt");

推荐答案

execl 函数调用不会为您拆分参数.基本上,这意味着调用函数时,需要将每个命令行参数分隔为不同的字符串参数.例如:

The execl function call does not split the arguments for you. This basically means that you need to separate each command line argument as a different string parameter when invoking the function. For example:

execl("C::\\WINDOWS\\SYSTEM32\\CMD.EXE", "cmd.exe", "/c", 
      "echo", "foo", ">C:\\Users\\Sarp\\Desktop\\foo.txt")

但是,我的印象是输出重定向可能不起作用(取决于Windows Shell如何解释这些重定向),所以我鼓励您尝试

However, I'm under the impression that the output redirection may not work (depending on how the Windows shell interprets those), so I encourage you to try the system() function which resembles your usage case more closely.

这篇关于C-在Windows中使用exec()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆