How do I programatically run a dos command like 'dir' (I assume this will be
the same way as running normal files, which I'd like to know how to do too).
Also, will the output from this go into stdout?
Is there any better way to get a list of files in a directory than parsing a
'dir' ?
Thanks,
J 6 1332
"Jeremy" <jo******@n0sp4mhotmail.com> writes: How do I programatically run a dos command like 'dir' (I assume this will be the same way as running normal files, which I'd like to know how to do too).
This is a FAQ.
19.27: How can I invoke another program (a standalone executable,
or an operating system command) from within a C program?
A: Use the library function system(), which does exactly that.
Note that system's return value is at best the command's exit
status (although even that is not guaranteed), and usually has
nothing to do with the output of the command. Note also that
system() accepts a single string representing the command to be
invoked; if you need to build up a complex command line, you can
use sprintf(). See also question 19.30.
References: K&R1 Sec. 7.9 p. 157; K&R2 Sec. 7.8.4 p. 167,
Sec. B6 p. 253; ISO Sec. 7.10.4.5; H&S Sec. 19.2 p. 407; PCS
Sec. 11 p. 179.
Also, will the output from this go into stdout?
Normally.
Is there any better way to get a list of files in a directory than parsing a 'dir' ?
This is also a FAQ.
19.20: How can I read a directory in a C program?
A: See if you can use the opendir() and readdir() functions, which
are part of the POSIX standard and are available on most Unix
variants. Implementations also exist for MS-DOS, VMS, and other
systems. (MS-DOS also has FINDFIRST and FINDNEXT routines which
do essentially the same thing.) readdir() only returns file
names; if you need more information about the file, try calling
stat(). To match filenames to some wildcard pattern, see
question 13.7.
References: K&R2 Sec. 8.6 pp. 179-184; PCS Sec. 13 pp. 230-1;
POSIX Sec. 5.1; Schumacher, ed., _Software Solutions in C_
Sec. 8.
--
"Large amounts of money tend to quench any scruples I might be having."
-- Stephan Wilms
"Jeremy" <jo******@n0sp4mhotmail.com> writes: How do I programatically run a dos command like 'dir' (I assume this will be the same way as running normal files, which I'd like to know how to do too). Also, will the output from this go into stdout?
Use the system() function, e.g.:
system("dir");
The output of the "dir" command will normally go to stdout.
Is there any better way to get a list of files in a directory than parsing a 'dir' ?
There are a number of better ways, but none of them are portable (the
C standard has no concept of directories). You'll need to ask in a
newsgroup that's specific to your operating system.
--
Keith Thompson (The_Other_Keith) 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.
Thanks, most helpful, where can I get my hands on the whole FAQ?
J
"Ben Pfaff" <bl*@cs.stanford.edu> wrote in message
news:87************@benpfaff.org... "Jeremy" <jo******@n0sp4mhotmail.com> writes:
How do I programatically run a dos command like 'dir' (I assume this
will be the same way as running normal files, which I'd like to know how to do
too). This is a FAQ.
19.27: How can I invoke another program (a standalone executable, or an operating system command) from within a C program?
A: Use the library function system(), which does exactly that. Note that system's return value is at best the command's exit status (although even that is not guaranteed), and usually has nothing to do with the output of the command. Note also that system() accepts a single string representing the command to be invoked; if you need to build up a complex command line, you can use sprintf(). See also question 19.30.
References: K&R1 Sec. 7.9 p. 157; K&R2 Sec. 7.8.4 p. 167, Sec. B6 p. 253; ISO Sec. 7.10.4.5; H&S Sec. 19.2 p. 407; PCS Sec. 11 p. 179.
Also, will the output from this go into stdout?
Normally.
Is there any better way to get a list of files in a directory than
parsing a 'dir' ?
This is also a FAQ.
19.20: How can I read a directory in a C program?
A: See if you can use the opendir() and readdir() functions, which are part of the POSIX standard and are available on most Unix variants. Implementations also exist for MS-DOS, VMS, and other systems. (MS-DOS also has FINDFIRST and FINDNEXT routines which do essentially the same thing.) readdir() only returns file names; if you need more information about the file, try calling stat(). To match filenames to some wildcard pattern, see question 13.7.
References: K&R2 Sec. 8.6 pp. 179-184; PCS Sec. 13 pp. 230-1; POSIX Sec. 5.1; Schumacher, ed., _Software Solutions in C_ Sec. 8. -- "Large amounts of money tend to quench any scruples I might be having." -- Stephan Wilms
"Jeremy" <jo******@n0sp4mhotmail.com> writes: Thanks, most helpful, where can I get my hands on the whole FAQ?
What, is Google down?
--
Ben Pfaff
email: bl*@cs.stanford.edu
web: http://benpfaff.org
"Jeremy" <jo******@n0sp4mhotmail.com> writes: Thanks, most helpful, where can I get my hands on the whole FAQ?
Google "C FAQ"; it's the first link.
--
Keith Thompson (The_Other_Keith) 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: David Faden |
last post by:
Hi,
Given arbitrary Python source code input by the user, I want to get the
result of executing that source as an expression if it is an expression
and otherwise execute the source as a...
|
by: Jagannathan Santhanam |
last post by:
Hello
I am trying to execute ‘xp_cmdshell' from within a DTS package that
was created by another person. When I try to execute that ‘SQL Task'
selectively from within the package, I get the...
|
by: Chakkaradeep |
last post by:
Hi all,
i have written a Service,now i want to execute another application (for
eg;calc.exe) in the service....how will i perform it??...
i tried using this....
/**************Executing a...
|
by: Pratibha |
last post by:
Hi,
I want to execute commands through .NET.
Using process, i can execute them in WindowsApplication but the process
doesn't work in WebApplication.
I am executing a batch file which contains...
|
by: kd |
last post by:
Hi All,
Would anybody be able to post me the command used in vb.net to execute an
application from within the current application?
Thanks.
kd
|
by: BasicQ |
last post by:
I am running an executable from my aspx page with the click of a
button. A date is passed as an argument. I am able to get the
standardoutput from the Process(Exe) into the label of my page after...
|
by: tshad |
last post by:
I thought I understood how the SaveViewState is working and was trying to
use this (as per some code I found) to detect refreshes. It seemed to be
working but I found that the SaveViewState was...
|
by: lovecreatesbea... |
last post by:
K&R 2, sec 2.4 says: If the variable in question is not automatic, the
initialization is done once only, conceptually before the program
starts executing, ... .
"Non-automatic variables are...
|
by: reycri |
last post by:
Hi,
I need to be able to do this:
var func = new Function("var me = <selfRef>; alert(me.params);");
func.params = "This is a test parameter";
window.setTimeout(func, 500);
Basically, I...
|
by: somuchh8 |
last post by:
Hi, I'm having a lot of trouble with the Win32::Spawn module in perl. Here is my situation, I have a Win32::Spawn call which looks like this:
my $success = undef;
my $cmdline =...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
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...
|
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,...
|
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...
|
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,...
| |