使用系统功能 [英] Use of System function

查看:65
本文介绍了使用系统功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我对C不熟悉。我想知道如何使用''系统''

功能。我的意思是我知道该函数用于运行外部

DOS命令,但每次使用它时都会返回-1,这意味着无法执行

命令。 br />
请帮助我............

Hi Guys,
I am little new to C. I wish to know the way to use the ''system''
function. I mean I know that the function is used to run an external
DOS command but every time I use it it returns -1 which meansthe
command could not be executed.
Kindly help me............

推荐答案

BHARAT MEHTA写道:
BHARAT MEHTA wrote:
大家好,我是C的小新手。我想知道如何使用''系统''
功能。我的意思是我知道该函数用于运行外部的DOS命令,但每次使用它都会返回-1,这意味着无法执行
命令。
Hi Guys,
I am little new to C. I wish to know the way to use the ''system''
function. I mean I know that the function is used to run an external
DOS command but every time I use it it returns -1 which meansthe
command could not be executed.




system()使用shell(DOS / Windows上的COMMAND.COM,Unix上的/ bin / sh

)来执行指定的命令。如果您只是给一个程序

名称,例如`unzip'',那么`unzip''必须位于PATH环境变量的
中指定的目录中。可以肯定的是,使用绝对路径来执行可执行文件,例如:


system(" / usr / games / fortune");

system(" C:\Program Files \Winzip \wzip32.exe");


有些系统可能没有shell的概念。对于那些,系统()

是无操作。您可以通过调用

system()并使用参数NULL来检查shell的存在,并检查返回值。

如果非零,则shell为可用。


HTH,

拉尔夫


-

Ralph Moritz


嘲笑你的问题;其他人都这样做。



system() uses the shell (COMMAND.COM on DOS/Windows, /bin/sh
on Unix) to execute the specified command. If you just give a program
name such as `unzip'', then `unzip'' must be in a directory specfied in
the PATH environment variable. To be sure, use an absolute path to
the executable, eg.

system("/usr/games/fortune");
system("C:\Program Files\Winzip\wzip32.exe");

Some systems may have no notion of a shell. For those, system()
is a no-op. You can check for the presence of a shell by calling
system() with an argument of NULL, and checking the return value.
If non-zero, a shell is available.

HTH,
Ralph

--
Ralph Moritz

Laugh at your problems; everybody else does.


" Ralph A. Moritz"写道:
"Ralph A. Moritz" writes:
BHARAT MEHTA写道:
BHARAT MEHTA wrote:
大家好,我是C的小新手。我想知道如何使用' '系统''
功能。我的意思是我知道该函数用于运行外部的DOS命令,但每次使用它都会返回-1,这意味着无法执行
命令。
Hi Guys,
I am little new to C. I wish to know the way to use the ''system''
function. I mean I know that the function is used to run an external
DOS command but every time I use it it returns -1 which meansthe
command could not be executed.



system()使用shell(DOS / Windows上的COMMAND.COM,Unix上的/ bin / sh
)来执行指定的命令。如果你只是给一个程序名称,例如`unzip'',那么`unzip''必须位于PATH环境变量中指定的目录中。可以肯定的是,使用绝对路径来执行可执行文件,例如系统(/ usr / games / fortune);
系统(C:\\ \\程序文件\ _Winzip \ wzip32.exe");



system() uses the shell (COMMAND.COM on DOS/Windows, /bin/sh
on Unix) to execute the specified command. If you just give a program
name such as `unzip'', then `unzip'' must be in a directory specfied in
the PATH environment variable. To be sure, use an absolute path to
the executable, eg.

system("/usr/games/fortune");
system("C:\Program Files\Winzip\wzip32.exe");




如果第二个不起作用,请检查转义序列WRT''\ ''

字符..



If that second one doesn''t work check up on escape sequences WRT the ''\''
character..




" osmium" < R 1 ******** @ comcast.net>在消息中写道

news:48 ************ @ individual.net ...

"osmium" <r1********@comcast.net> wrote in message
news:48************@individual.net...
" Ralph A. Moritz"写道:
"Ralph A. Moritz" writes:
BHARAT MEHTA写道:
BHARAT MEHTA wrote:
大家好,我是C的小新手。我想知道如何使用' '系统''
功能。我的意思是我知道该函数用于运行外部的DOS命令,但每次使用它都会返回-1,这意味着无法执行
命令。
Hi Guys,
I am little new to C. I wish to know the way to use the ''system''
function. I mean I know that the function is used to run an external
DOS command but every time I use it it returns -1 which meansthe
command could not be executed.



system()使用shell(DOS / Windows上的COMMAND.COM,Unix上的/ bin / sh
)来执行指定的命令。如果你只是给一个程序名称,例如`unzip'',那么`unzip''必须位于PATH环境变量中指定的目录中。可以肯定的是,使用绝对路径来执行可执行文件,例如系统(/ usr / games / fortune);
系统(C:\\ \\ Program Program \ _Winzip \ wzip32.exe");



system() uses the shell (COMMAND.COM on DOS/Windows, /bin/sh
on Unix) to execute the specified command. If you just give a program
name such as `unzip'', then `unzip'' must be in a directory specfied in
the PATH environment variable. To be sure, use an absolute path to
the executable, eg.

system("/usr/games/fortune");
system("C:\Program Files\Winzip\wzip32.exe");



如果第二个没有工作,请检查转义序列WRT''\''
character ..



If that second one doesn''t work check up on escape sequences WRT the ''\''
character..




第二个确实有效,对于MS-DOS是正确的。 system()中的字符串

直接传递给操作系统的命令处理器_AS_IS_。对于MS-DOS

command.com命令行,不需要像printf()那样转义反斜杠''\''

字符。



The second one does work and is correct for MS-DOS. The string in system()
passed directly to the OS''s command processor _AS_IS_. For the MS-DOS
command.com command line, one does not need to escape the backslash ''\''
character as you would for printf().


这篇关于使用系统功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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