473,791 Members | 3,211 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to access the stdout file

Hello,
I am trying to find a way to take the contents of a directory and
write it into a file. I have a directory that has several hundred text
files, and I want to create a file containing all of the names of those
files. I can get the contents of the directory onto the screen using
system("dir"); But I have not been able to get this data into a file.
I understand that stdout is a pointer to a file, and so I should be
able to open and read this file without physically viewing the screen.
Anyway, any ideas? Thanks in advance.

andrew

Oct 4 '06 #1
13 3498

Andrew wrote:
Anyway, any ideas? Thanks in advance.
What OS are you using?

Oct 4 '06 #2
"Andrew" <an************ @gmail.comwrite s:
I am trying to find a way to take the contents of a directory and
write it into a file. I have a directory that has several hundred text
files, and I want to create a file containing all of the names of those
files. I can get the contents of the directory onto the screen using
system("dir"); But I have not been able to get this data into a file.
I understand that stdout is a pointer to a file, and so I should be
able to open and read this file without physically viewing the screen.
Ask in a newsgroup that deals with your operating system. Standard C
doesn't even have a concept of directories.

--
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.
Oct 4 '06 #3

Andrew wrote:
Hello,
I am trying to find a way to take the contents of a directory and
write it into a file. I have a directory that has several hundred text
files, and I want to create a file containing all of the names of those
files. I can get the contents of the directory onto the screen using
system("dir"); But I have not been able to get this data into a file.
I understand that stdout is a pointer to a file, and so I should be
able to open and read this file without physically viewing the screen.
Anyway, any ideas? Thanks in advance.

andrew
If you can use system("dir"); , why don't you use the command "dir * >
filenames.txt" to get what you want?

Oct 4 '06 #4

"Andrew" <an************ @gmail.comwrote in message
news:11******** ************@h4 8g2000cwc.googl egroups.com...
Hello,
I am trying to find a way to take the contents of a directory and
write it into a file. I have a directory that has several hundred text
files, and I want to create a file containing all of the names of those
files. I can get the contents of the directory onto the screen using
system("dir"); But I have not been able to get this data into a file.
I understand that stdout is a pointer to a file, and so I should be
able to open and read this file without physically viewing the screen.
Anyway, any ideas? Thanks in advance.

andrew
Probably your operating system has a specific system call for
enumarating the contents of directories. If it is windows, as it
seems from the dir command you are using then check the
FindFirstFile and FindNextFile system calls.

For more info, you should ask again in a related group.

Serafeim
Oct 4 '06 #5

"Papastefan os Serafeim" <se******@otene t.grwrote in message
news:ef******** ***@ulysses.noc .ntua.gr...
>
"Andrew" <an************ @gmail.comwrote in message
[system specific question}
Probably your operating system has a specific system call for
enumarating the contents of directories. If it is windows, as it
seems from the dir command you are using then check the
FindFirstFile and FindNextFile system calls.

For more info, you should ask again in a related group.

Serafeim
I was going to accuse you of misspelling seraphim in your moniker, but since
you're greek, I'm going to let that one go. OP needs to rephrase the
question to make it topical. Since he has the odor of windows, he can
expect the customary tomato in the face in clc.

Set the "sort by" on your newsreader to "subject" and look for "Parsing a
path name" to see how it is that one can talk about path in a manner
relevant to the C programming language. The other half of the question is
how to redirect stdout to a file, which I don't pretend to know. EC

p.s. Don't get stung by '/' vs '\'; I can only ever remember it's one or the
other.
Oct 4 '06 #6

"Andrew" <an************ @gmail.comwrote in message
news:11******** ************@h4 8g2000cwc.googl egroups.com...
Hello,
I am trying to find a way to take the contents of a directory and
write it into a file. I have a directory that has several hundred text
files, and I want to create a file containing all of the names of those
files. I can get the contents of the directory onto the screen using
system("dir");
I guess at this point I should include the usual disclaimer. Standard "C"
know nothing about the "system" call, its a (fairly common) extension. But
it is an extension.
But I have not been able to get this data into a file.
I understand that stdout is a pointer to a file, and so I should be
able to open and read this file without physically viewing the screen.
Thats because system creates a seperate process. As others have pointed out
you can do something like:-

system("dir /b >files.txt")l

but of course if there is already a "files.txt" you are in trouble....
Possiblly something like:-

system("dir /b >%tmp%\files.tx t");

is safer, but then you need to find out whats in %tmp% in order to open it
and read it....
Anyway, any ideas? Thanks in advance.

andrew
Dave.
Oct 4 '06 #7
In article <Uc************ ********@eclips e.net.uk>,
David Wade <g8***@yahoo.co mwrote:
>
"Andrew" <an************ @gmail.comwrote in message
news:11******* *************@h 48g2000cwc.goog legroups.com...
>Hello,
I am trying to find a way to take the contents of a directory and
write it into a file. I have a directory that has several hundred text
files, and I want to create a file containing all of the names of those
files. I can get the contents of the directory onto the screen using
system("dir" );

I guess at this point I should include the usual disclaimer. Standard "C"
know nothing about the "system" call, its a (fairly common) extension. But
it is an extension.
Actually, standard "C" has a system() function. It just doesn't say
anything (*) about what it does.

(*) There's an exception to this - others will no doubt chime in with it
by and by.

Oct 4 '06 #8

"Kenny McCormack" <ga*****@xmissi on.xmission.com wrote in message
news:eg******** **@news.xmissio n.com...
In article <Uc************ ********@eclips e.net.uk>,
David Wade <g8***@yahoo.co mwrote:

"Andrew" <an************ @gmail.comwrote in message
news:11******** ************@h4 8g2000cwc.googl egroups.com...
Hello,
I am trying to find a way to take the contents of a directory and
write it into a file. I have a directory that has several hundred text
files, and I want to create a file containing all of the names of those
files. I can get the contents of the directory onto the screen using
system("dir");
I guess at this point I should include the usual disclaimer. Standard "C"
know nothing about the "system" call, its a (fairly common) extension.
But
it is an extension.

Actually, standard "C" has a system() function. It just doesn't say
anything (*) about what it does.

(*) There's an exception to this - others will no doubt chime in with it
by and by.
Kenny,
I must be getting old. I have read "The Standard C Library" many times and
always missed the stuff on SYSTEM. I guess as it inlcudes "getenv()" you can
"sort of" do this....
Dave.
Oct 4 '06 #9
David Wade wrote:
"Kenny McCormack" <ga*****@xmissi on.xmission.com wrote in message
news:eg******** **@news.xmissio n.com...
>In article <Uc************ ********@eclips e.net.uk>,
David Wade <g8***@yahoo.co mwrote:
>>"Andrew" <an************ @gmail.comwrote in message
news:11****** **************@ h48g2000cwc.goo glegroups.com.. .
Hello,
I am trying to find a way to take the contents of a directory and
write it into a file. I have a directory that has several hundred text
files, and I want to create a file containing all of the names of those
files. I can get the contents of the directory onto the screen using
system("dir" );
I guess at this point I should include the usual disclaimer. Standard "C"
know nothing about the "system" call, its a (fairly common) extension.
But
>>it is an extension.
Actually, standard "C" has a system() function. It just doesn't say
anything (*) about what it does.

(*) There's an exception to this - others will no doubt chime in with it
by and by.

Kenny,
I must be getting old. I have read "The Standard C Library" many times and
always missed the stuff on SYSTEM. I guess as it inlcudes "getenv()" you can
"sort of" do this....
Dave.
system(const char *s) is in stlib.h

"If s is not a null pointer, the function passes the string s to be
executed by a command processor, supplied by the target environment, and
returns the status reported by the command processor. If s is a null
pointer, the function returns nonzero only if the target environment
supplies a command processor. Each implementation defines what strings
its command processor accepts."
Oct 4 '06 #10

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

Similar topics

6
5640
by: Tsai Li Ming | last post by:
Dear all, I have a problem with a redirecting stdout and stderr. I am a top level module and has no control over the imported modules that are making system calls such as os.system or popen2.* . I have tried the simplest method of capturing stdout, stderr via: saveout = sys.stdout sys.stdout = file_obj
4
2320
by: Leon | last post by:
"stdout" is file object, it open mode is "w" and it have a close() fuction..... while it run close(), how to reopen it because I want to do rewrite it stdout content update
7
3976
by: Mike | last post by:
I would like my 'print' statements to send its output to the user's screen and a log file. This is my initial attempt: class StdoutLog(file): def __init__(self, stdout, name='/tmp/stdout.log', mode='w',bufsize=-1): super(StdoutLog, self).__init__(name,mode,bufsize) self.stdout = stdout
31
2034
by: Randy Yates | last post by:
When I try fprintf(file, "Report of File %s\n", sMF->fileName); I get a core dump. This works fine if fprintf is changed to sprintf and a string buffer used instead as the first parameter. It looks like the standard descriptors are not really open.
9
18292
by: Santtu Nyrhinen | last post by:
Hi, Let say that I have a function like void writeHello() { printf("Hello"); } Now I need to make an automated test fot that function. The test function returns 1 for successful and 0 for unsuccessful test. int Test_writeHello() {
4
11292
by: xman | last post by:
I'm looking for a C/C++ library that can get access to the stdin and stdout of a process. I may invoke a external program in a C/C++ program, but how do write data into the stdin of the external program, and read data out from the stdout of the external program? Suggestions are much appreciated.
7
384
by: MisterPete | last post by:
How can I inherit from file but stil create an instance that writes to stdout? ----------- I'm writing a file-like object that has verbosity options (among some other things). I know I could just set self.file to a file object rather than inheriting from file. I started with something like this (simplified for clarity): class Output(object): def __init__(self, file=sys.stdout, verbosity=1):
5
2614
by: =?gb2312?B?yMvR1MLkyNXKx8zs0cSjrM37vKvM7NHEsru8+7z | last post by:
I wanna print the log to both the screen and file, so I simulatered a 'tee' class Tee(file): def __init__(self, name, mode): file.__init__(self, name, mode) self.stdout = sys.stdout sys.stdout = self
4
2297
by: lovecreatesbea... | last post by:
For example, in Bourne Shell both stdout and stderr can be re-directed to /dev/null, $ ./a.out 2>&1 /dev/null then is there any difference still?
0
9666
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9512
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10147
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9987
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 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...
0
9023
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5552
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4100
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
2
3709
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2910
bsmnconsultancy
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...

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.