473,471 Members | 2,017 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

accessing dos from c program

how should you access the dos os from a c program whuch as djgpp?

need to write an app that would for example get a list of all *.h
files and store them in a linked list so the names need to be
parsable......

seems straight forward on unix, but need to do it from a dos window on
a win98 platform.

cheers
JohnO


Nov 14 '05 #1
4 3504

"JakeP" <sp*********@hotmail.com> wrote in message

need to write an app that would for example get a list of all *.h
files and store them in a linked list so the names need to be
parsable......

The standard library has no directory functions, so you need to use an
extension.
Nov 14 '05 #2
On Sat, 13 Dec 2003 12:43:35 +0000, JakeP <sp*********@hotmail.com>
wrote:
how should you access the dos os from a c program whuch as djgpp?

need to write an app that would for example get a list of all *.h
files and store them in a linked list so the names need to be
parsable......

seems straight forward on unix, but need to do it from a dos window on
a win98 platform.


Guh. There is no C standard library call to traverse a directory.
Study your platform and its API. IIRC, in Win32, you need
FindFirstFile. _findfirst may also be available, depending on your
compiler.

- Sev

Nov 14 '05 #3
JakeP wrote:
how should you access the dos os from a c program whuch as djgpp?

need to write an app that would for example get a list of all *.h
files and store them in a linked list so the names need to be
parsable......

seems straight forward on unix, but need to do it from a dos window on
a win98 platform.


The basic answer is to use system(). Any other answer -- for unix or
windows or dos or any of many other choices -- takes us beyond standard C.
Below is an example of use.
Notes:
The string argument to system(), unless it is null, has no meaning in
C: it is up to your command processor to determine its meaning.
This example does not include the redirection to a file that would be
needed for your application.
The particulars of system() and its interaction with various possible
shells can be complicated for djgpp. Read your documentation for the (off
topic) details.
Your (off topic) <dir.h>, <sys/dir.h>, and <dirent.h> functions are
mostly supported under djgpp. Because these are not standard C functions,
you need to direct any questions -- after reading the documentation -- to
comp.os.msdos.djgpp, the djgpp mailing list, or one of the gnu.* newsgroups.

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
if (!system(0)) {
printf("No shell available for system()\n");
exit(EXIT_FAILURE);
}
else { /* DOS specific crap */
char *shell = getenv("SHELL");
char *comspec = getenv("COMSPEC");
printf("DOS specific crap:\n"
"SHELL: \"%s\"\n"
"COMSPEC: \"%s\"\n",
((shell) ? shell : "not found"),
((comspec) ? comspec : "not found"));
putchar('\n');
printf("system(\"dir *.h\") returned %d\n", system("dir *h"));
putchar('\n');
printf("system(\"../rundos \"dir *.h\"\") returned %d\n",
system("../rundos \"dir *h\""));
putchar('\n');
printf("system(\"ls -l *.h\") returned %d\n",
system("ls -l *h"));
return 0;
}
}
DOS specific crap:
SHELL: "C:\WINDOWS\SYSTEM32\COMMAND.COM"
COMSPEC: "C:\WINDOWS\SYSTEM32\COMMAND.COM"

crap.h
system("dir *.h") returned 0
Volume in drive C has no label
Volume Serial Number is 3466-C6BD
Directory of C:\MARTIN\C

CRAP H 750 12/13/03 3:38p
1 file(s) 750 bytes
1023932928 bytes free
system("../rundos "dir *.h"") returned 0

-rw-r--r-- 1 dosuser root 750 Dec 13 15:38 crap.h
system("ls -l *.h") returned 0
--
Martin Ambuhl

Nov 14 '05 #4

"JakeP" <sp*********@hotmail.com> wrote in message
news:0v********************************@4ax.com...
how should you access the dos os from a c program whuch as djgpp?

need to write an app that would for example get a list of all *.h
files and store them in a linked list so the names need to be
parsable......

seems straight forward on unix, but need to do it from a dos window on
a win98 platform.

cheers
JohnO

If you are using djgpp, use the dirent.h functions. If not, and your
compiler has no equilivent, use DOS's software interrupts. See Ralf Brown's
Interrupt list:
http://www-2.cs.cmu.edu/afs/cs.cmu.e...WWW/files.html
DrX
Nov 14 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Tom Meuzelaar | last post by:
Hello: I'm using VB6 in VS enterprise. I'd like to place an HTML form inside a VB container, have a user fill out the form information, click a submit button, and then have the program capture...
4
by: Jaydeep | last post by:
Hello, I am facing a strange problem. Problem accessing remote database from ASP using COM+ server application having VB components (ActiveX DLL) installed. Tier 1 : ASP front End (IIS 5.0) Tire...
13
by: lupher cypher | last post by:
Hi, I'm trying to access memory directly at 0xb800 (text screen). I tried this: char far* screen = (char far*)0xb8000000; but apparently c++ compiler doesn't know "far" (says "syntax error...
6
by: Alex5222 | last post by:
I am making a program in C++ and was wondering how to make a program access and change the registry. Any help would be greatly appreciated. Thanks.
3
by: diephouse | last post by:
I seem to be having a problem accessing networks shares. For example, I try the following code: File.Exists(@"\\SERVER\share"); always returns false! Or even if I map the drive ...
1
by: mbah Sumani via .NET 247 | last post by:
(Type your message here) I Think it's the stupidness of Windows. Why the service can't access network drive but console apps or windows application can do it? So my suggestion is make the program...
3
by: AdamM | last post by:
Hi all, When I run my VbScript, I get the error: "ActiveX component can't create object: 'getobject'. Error 800A01AD". Any ideas what I did wrong? Here's my VBScript: dim o set...
2
by: rwise5 | last post by:
I am wondering if someone can help me with the following C programming problem. I am trying to develop a program dealing with input/output and files . I am trying to develop a program that...
6
by: Sid | last post by:
All, See the below piece of C code snippet typedef struct _a { int ia; int ja; }A;
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.