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............ 16 2138
BHARAT MEHTA wrote: 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() 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:\Prog ram Files\Winzip\wz ip32.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" writes: BHARAT MEHTA wrote: 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() 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:\Prog ram Files\Winzip\wz ip32.exe");
If that second one doesn't work check up on escape sequences WRT the '\'
character..
"osmium" <r1********@com cast.net> wrote in message
news:48******** ****@individual .net... "Ralph A. Moritz" writes:
BHARAT MEHTA wrote: 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() 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:\Prog ram Files\Winzip\wz ip32.exe");
If that second one doesn't work check up on escape sequences WRT the '\' character..
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().
On 2006-03-29, Rod Pemberton <do*********@so rry.bitbuck.cmm > wrote: "osmium" <r1********@com cast.net> wrote in message news:48******** ****@individual .net... "Ralph A. Moritz" writes:
> BHARAT MEHTA wrote: >> 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() 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:\Prog ram Files\Winzip\wz ip32.exe");
If that second one doesn't work check up on escape sequences WRT the '\' character..
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().
Eh?
You _always_ need to escape the backslash when it appears in a string
literal. It's not printf that interprets it, it's the compiler. It's not
like a % sequence.
"Rod Pemberton" <do*********@so rry.bitbuck.cmm > writes: "osmium" <r1********@com cast.net> wrote in message news:48******** ****@individual .net... "Ralph A. Moritz" writes: > BHARAT MEHTA wrote: >> 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() 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:\Prog ram Files\Winzip\wz ip32.exe");
If that second one doesn't work check up on escape sequences WRT the '\' character..
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().
Wrong. (Did you actually try it?)
The argument to system() is a string literal, and is interpreted
according to C's rules for string literals. The fact that it's an
argument to system() is irrelevant.
Since the language doesn't define the escape sequences \P, \W, or \w,
strictly speaking the argument isn't even a valid token, and a
diagnostic is required. After the diagnostic is issued, the compiler
can do anything it likes, including rejecting the program. It could
conceivably treat "\P" as equivalent to "\\P", but that would be a bad
idea, since it's not allowed to mess with \a, \b, \f, \n, \r, \t, or \v.
(The rules are more lax for #include directives, since in
#include "foobar.h"
the "foobar.h" isn't actually a string literal.)
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
"Keith Thompson" <ks***@mib.or g> wrote in message
news:ln******** ****@nuthaus.mi b.org... "Rod Pemberton" <do*********@so rry.bitbuck.cmm > writes: "osmium" <r1********@com cast.net> wrote in message news:48******** ****@individual .net... "Ralph A. Moritz" writes: > BHARAT MEHTA wrote: >> 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() 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:\Prog ram Files\Winzip\wz ip32.exe");
If that second one doesn't work check up on escape sequences WRT the
'\' character.. 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().
Wrong. (Did you actually try it?)
I have existing code which does the same thing (which I which consulted
prior to my post). No escapes are needed and it works with multiple DOS
based compilers.
The argument to system() is a string literal, and is interpreted according to C's rules for string literals. The fact that it's an argument to system() is irrelevant.
Apparently not. I haven't checked the ISO spec., but Harbison and Steele
agrees with me that the string from system() is passed as is to the OS in an
implementation defined manner.
"Jordan Abel" <ra*******@gmai l.com> wrote in message
news:sl******** *************** @random.yi.org. .. On 2006-03-29, Rod Pemberton <do*********@so rry.bitbuck.cmm > wrote: "osmium" <r1********@com cast.net> wrote in message news:48******** ****@individual .net... "Ralph A. Moritz" writes:
> BHARAT MEHTA wrote: >> 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() 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:\Prog ram Files\Winzip\wz ip32.exe");
If that second one doesn't work check up on escape sequences WRT the
'\' character..
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().
Eh?
You _always_ need to escape the backslash when it appears in a string literal. It's not printf that interprets it, it's the compiler. It's not like a % sequence.
See my reply to Keith.
Jordan Abel <ra*******@gmai l.com> writes: On 2006-03-29, Rod Pemberton <do*********@so rry.bitbuck.cmm > wrote: "osmium" <r1********@com cast.net> wrote in message news:48******** ****@individual .net... "Ralph A. Moritz" writes:
[...] > system("/usr/games/fortune"); > system("C:\Prog ram Files\Winzip\wz ip32.exe");
If that second one doesn't work check up on escape sequences WRT the '\' character..
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().
Eh?
You _always_ need to escape the backslash when it appears in a string literal. It's not printf that interprets it, it's the compiler. It's not like a % sequence.
You're right, printf doesn't interpret the argument to system(). 8-)}
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
"Rod Pemberton" <do*********@so rry.bitbuck.cmm > writes: "Keith Thompson" <ks***@mib.or g> wrote in message news:ln******** ****@nuthaus.mi b.org... "Rod Pemberton" <do*********@so rry.bitbuck.cmm > writes: > "osmium" <r1********@com cast.net> wrote in message > news:48******** ****@individual .net... >> "Ralph A. Moritz" writes:
[...] >> > system("/usr/games/fortune"); >> > system("C:\Prog ram Files\Winzip\wz ip32.exe"); >> >> If that second one doesn't work check up on escape sequences WRT >> the '\' character.. > > 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(). Wrong. (Did you actually try it?)
I have existing code which does the same thing (which I which consulted prior to my post). No escapes are needed and it works with multiple DOS based compilers.
If so, the compilers in question may be providing an extension. If
they don't produce a diagnostic, they're non-conforming.
Show us a complete and self-contained C program that supports your
claim. For example:
#include <stdlib.h>
int main(void)
{
system("...");
return 0;
}
where "..." is replaced with whatever you like. Make sure it actually
works with some MS-DOS compiler (and tell us which one).
If you're able to do that, see what happens if the argument contains
one of the standard escape sequences: \a \b \f \n \r \t \v. If any of
those is interpreted as something other than an alert, backspace, form
feed, new line, carriage return, horizontal tab, or vertical tab
charater, respectively, then your compiler is broken. The argument to system() is a string literal, and is interpreted according to C's rules for string literals. The fact that it's an argument to system() is irrelevant.
Apparently not. I haven't checked the ISO spec.,
I suggest you do so.
but Harbison and Steele agrees with me that the string from system() is passed as is to the OS in an implementation defined manner.
You've misinterpreted Harbison and Steele. The string argument is
passed to the operating system's command processor for execution in
some implementation-defined way, but any implementation-defined
behavior occurs only after the string is passed to system(). The
evaluation of the argument expression is not affected by the fact that
it's in a call to system().
This:
"C:\Program Files\Winzip\wz ip32.exe"
is not a valid C token (except possibly in a #include directive).
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: monkey king |
last post by:
I have a given dll file(PDFCreator.dll) - probably generated by VC++.
I want to use its method(PDFCreator()) in dotNet environment. It works
well in WindiowsApplication, but bad in WebApplication ,the line that
calls the function results in the "Object reference not set to an
instance of an object" error.
The following is the VB.NET code I am using to define the structures,
declare the unmanaged DLL function and call the unmanaged DLL...
|
by: Phil Stanton |
last post by:
When designing a new form or report, the Default ForeColor is often
something like -2147483640 which is the colour of Windows text (possibly
black) and the default backColor is -2147483643 (possibly white)
Can anyone tell me how to convert these colours to either RGB colours or the
Long number used by Access. Black is 0 and White is 16777215
...
|
by: AussieRules |
last post by:
Hi,
I want to use the user color scheme to set the color of my forms.
I now I have to use the. System.Drawing.SystemColors, but which color is the
color of a form background as used in other applications.
In the end all I want to do is
form1.backcolor = system.whatever.color
|
by: Lance |
last post by:
I want to expose properties of a class to a user via a PropertyGrid class. Some of the properties are of type System.IO.FileInfo. Ideally, an OpenFileDialog window would appear when the user attempted to edit the value of the System.IO.FileInfo properties. Is there an existing UITypeEditor that will do this type of thing, or will I need to create my own
Thanks
Lance
|
by: Arthur Dent |
last post by:
How do you sort a generic collection derived from
System.Collections.ObjectModel.Collection?
Thanks in advance,
- Arthur Dent
| |
by: prasadjoshi124 |
last post by:
Hi All,
I am writing a small tool which is supposed to fill the filesystem to a
specified percent.
For, that I need to read how much the file system is full in percent,
like the output given by df -k
lopgod10:~/mycrfile # df -k /mnt/mvdg1/vset
Filesystem 1K-blocks Used Available Use% Mounted on
|
by: Xah Lee |
last post by:
REQUIREMENTS FOR A VISUALIZATION SOFTWARE SYSTEM FOR 2010
Xah Lee, 2007-03-16
In this essay, i give a list of requirements that i think is necessary
for a software system for creating scientific visualization for the
next decade (2007-2017).
(for a HTML version with images, please see
http://xahlee.org/3d/viz.html )
|
by: schneider |
last post by:
I need to hook the system mouse down event.
I'm trying to replicate how a context menu hides when the mouse clicks
outside of the control.
Thanks,
Schneider
|
by: =?Utf-8?B?SmVycnkgQw==?= |
last post by:
I am using this code to get groups for a user and getting a error (5) on the
GetAuthorizationGroups() function .
There are two domains.
This function works on the local domain but does not work on the other domain.
Other functions work on the other domain like get all the users and get all
the groups and I can validate users on the other domain so I think I am
communciating with the other domain OK just not with the...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |