同样的命令bat能执行成功而c++的system为什么不能执行成功呢

IT小狼狗 2017-10-31 05:03:32
...全文
386 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
一脸懵逼哦 2019-07-14
  • 打赏
  • 举报
回复
有解决办法了吗,我也是郁闷了好久。非常简单的命令,执行对象不同,结果不同。cmd执行和程序里执行结果不同
赵4老师 2017-11-02
  • 打赏
  • 举报
回复
system, _wsystem Execute a command. int system( const char *command ); int _wsystem( const wchar_t *command ); Routine Required Header Compatibility system <process.h> or <stdlib.h> ANSI, Win 95, Win NT _wsystem <process.h> or <stdlib.h> or <wchar.h> Win NT For additional compatibility information, see Compatibility in the Introduction. Libraries LIBC.LIB Single thread static library, retail version LIBCMT.LIB Multithread static library, retail version MSVCRT.LIB Import library for MSVCRT.DLL, retail version Return Value If command is NULL and the command interpreter is found, the function returns a nonzero value. If the command interpreter is not found, it returns 0 and sets errno to ENOENT. If command is not NULL, system returns the value that is returned by the command interpreter. It returns the value 0 only if the command interpreter returns the value 0. A return value of – 1 indicates an error, and errno is set to one of the following values: E2BIG Argument list (which is system-dependent) is too big. ENOENT Command interpreter cannot be found. ENOEXEC Command-interpreter file has invalid format and is not executable. ENOMEM Not enough memory is available to execute command; or available memory has been corrupted; or invalid block exists, indicating that process making call was not allocated properly. Parameter command Command to be executed Remarks The system function passes command to the command interpreter, which executes the string as an operating-system command. system refers to the COMSPEC and PATH environment variables that locate the command-interpreter file (the file named CMD.EXE in Windows NT). If command is NULL, the function simply checks to see whether the command interpreter exists. You must explicitly flush (using fflush or _flushall) or close any stream before calling system. _wsystem is a wide-character version of system; the command argument to _wsystem is a wide-character string. These functions behave identically otherwise. Generic-Text Routine Mappings TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined _tsystem system system _wsystem Example /* SYSTEM.C: This program uses * system to TYPE its source file. */ #include <process.h> void main( void ) { system( "type system.c" ); } Output /* SYSTEM.C: This program uses * system to TYPE its source file. */ #include <process.h> void main( void ) { system( "type system.c" ); } Process and Environment Control Routines See Also _exec Functions, exit, _flushall, _spawn Functions
  • 打赏
  • 举报
回复
system命令是非阻塞执行的,注意这个问题,有可能system命令还没有完成,就要执行下一跳指令了。
CT8100 2017-10-31
  • 打赏
  • 举报
回复
引用 2 楼 zhao4zhong1 的回复:
cmd /c ...
原来如此~
赵4老师 2017-10-31
  • 打赏
  • 举报
回复
cmd /c ...
CT8100 2017-10-31
  • 打赏
  • 举报
回复
直接将system()执行bat的绝对路径呢?我猜测systeam不能识别bat的&&语法。。

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧