Hello, I'm new to c - so sorry if this is off topic here, please advice
at least where should i ask... ;)
I have a program in c which is working fine, it reads everything from
pipe, modifies output data a bit and writes to stdout.
When it is executed without parameters, program works fine. But what if
I'd like to pass some extra configuration parameters to my program?
1. c:\> pipetest < file_in > file_out // this works
2. c:\> pipetest /parameter < file_in // also works, writes
file_in and parameters to stdout
3. c:\> pipetest /parameter < file_in > file_out // nothing happens !?
Thanks anyone for kind advice and a nice day to all,
Y.
// pitest.c
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
int main(int argc,char *argv[]) {
int ch,i;
for (i = 1; i < argc; i++) {
printf("%s\n",argv[i]);
}
setmode(fileno(stdin), O_BINARY);
setmode(fileno(stdout), O_BINARY);
ch=getc(stdin);
while (!feof(stdin)) {
putc(ch,stdout);
}
}
// ------- 7 2230
<ja***********@seznam.cz> wrote in message news:43********@x-privat.org... Hello, I'm new to c - so sorry if this is off topic here, please advice at least where should i ask... ;)
I have a program in c which is working fine, it reads everything from pipe, modifies output data a bit and writes to stdout.
When it is executed without parameters, program works fine. But what if I'd like to pass some extra configuration parameters to my program?
1. c:\> pipetest < file_in > file_out // this works 2. c:\> pipetest /parameter < file_in // also works, writes file_in and parameters to stdout 3. c:\> pipetest /parameter < file_in > file_out // nothing happens !?
Thanks anyone for kind advice and a nice day to all, Y.
// pitest.c #include <stdio.h> #include <fcntl.h> #include <io.h>
int main(int argc,char *argv[]) { int ch,i; for (i = 1; i < argc; i++) { printf("%s\n",argv[i]); } setmode(fileno(stdin), O_BINARY); setmode(fileno(stdout), O_BINARY); ch=getc(stdin); while (!feof(stdin)) { putc(ch,stdout); } } // -------
Shouldn't the getc() call be inside the while loop?
"ja***********@seznam.cz" <ja***********@seznam.cz> wrote in
news:43********@x-privat.org: Hello, I'm new to c - so sorry if this is off topic here, please advice at least where should i ask... ;)
I have a program in c which is working fine, it reads everything from pipe, modifies output data a bit and writes to stdout.
When it is executed without parameters, program works fine. But what if I'd like to pass some extra configuration parameters to my program?
1. c:\> pipetest < file_in > file_out // this works 2. c:\> pipetest /parameter < file_in // also works, writes file_in and parameters to stdout 3. c:\> pipetest /parameter < file_in > file_out // nothing happens !?
Thanks anyone for kind advice and a nice day to all, Y.
// pitest.c #include <stdio.h> #include <fcntl.h> #include <io.h>
int main(int argc,char *argv[]) { int ch,i; for (i = 1; i < argc; i++) { printf("%s\n",argv[i]); } setmode(fileno(stdin), O_BINARY); setmode(fileno(stdout), O_BINARY); ch=getc(stdin); while (!feof(stdin)) { putc(ch,stdout); } }
a) Case #1 has no arguments to print because everything from the '<' over
is not passed to your program.
b) Case #3 will write "/parameter" to file_out, because that's where
you've redirected stdout, STUPID.
c) Your program will NOT copy stdin to stdout correctly; it will just
copy the first byte from stdin over and over until you stop the program,
you DUMBASS.
d) You are a fucking moron. Forget C and go play with dolls or
something.
Hake <ha***@third.floor> wrote: b) Case #3 will write "/parameter" to file_out, because that's where you've redirected stdout, STUPID.
(unwarranted flame snipped)
I would suggest demonstrating some civility, lest you be dealt with in
like fashion the next time a bug appears in your code. Not everyone
has the luxury of skipping the "beginning programmer" stage as you
apparently have.
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome. ja***********@seznam.cz <ja***********@seznam.cz> wrote: Hello, I'm new to c - so sorry if this is off topic here, please advice at least where should i ask... ;)
It isn't very topical; comp.unix.programmer is a good place to go
(assuming, perhaps incorrectly, that you are using a flavor of Unix).
You managed not to be totally off-topic, however...
// pitest.c #include <stdio.h> #include <fcntl.h> #include <io.h>
int main(int argc,char *argv[]) { int ch,i; for (i = 1; i < argc; i++) { printf("%s\n",argv[i]); } setmode(fileno(stdin), O_BINARY); setmode(fileno(stdout), O_BINARY); ch=getc(stdin); while (!feof(stdin)) { putc(ch,stdout); } }
Don't do it like that.
while( (ch=getc(stdin)) != EOF ) {
putc( ch, stdout );
}
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Hake wrote: "ja***********@seznam.cz" <ja***********@seznam.cz> wrote in news:43********@x-privat.org:
Hello, I'm new to c - so sorry if this is off topic here, please advice at least where should i ask... ;)
I have a program in c which is working fine, it reads everything from pipe, modifies output data a bit and writes to stdout.
When it is executed without parameters, program works fine. But what if I'd like to pass some extra configuration parameters to my program?
1. c:\> pipetest < file_in > file_out // this works 2. c:\> pipetest /parameter < file_in // also works, writes file_in and parameters to stdout 3. c:\> pipetest /parameter < file_in > file_out // nothing happens !?
Thanks anyone for kind advice and a nice day to all, Y.
// pitest.c #include <stdio.h> #include <fcntl.h> #include <io.h>
int main(int argc,char *argv[]) { int ch,i; for (i = 1; i < argc; i++) { printf("%s\n",argv[i]); } setmode(fileno(stdin), O_BINARY); setmode(fileno(stdout), O_BINARY); ch=getc(stdin); while (!feof(stdin)) { putc(ch,stdout); } }
a) Case #1 has no arguments to print because everything from the '<'
over is not passed to your program.
this point was clear to me :) b) Case #3 will write "/parameter" to file_out, because that's where you've redirected stdout, STUPID.
Oh no, right! I must admit you are right :( :( I'm really a dumb :( What
a contretemps.... c) Your program will NOT copy stdin to stdout correctly; it will just copy the first byte from stdin over and over until you stop the program, you DUMBASS.
The program I pasted here was wrong, original of my program is longer
and it was not point to bore anyone with that, when that worked. My loop
is working... my only mistake was I forgot to leave fgetc inside loop -
in original it's there of course... :) d) You are a fucking moron. Forget C and go play with dolls or something.
And you are a monkey, not a human :) btw. I prefer trainspotting before
playing with dolls... ;) But in some rare cases I need to make some
handy program. I'm not a programmer (as everyone yet noticed:)
Anyway, thank you for help, you are a bit rude, but you helped me, and
that was what I really needed :D btw. the question *wasn't* "what you
thing about my IQ", so you could have left the off topic notes for
yourself... ;) But I must admit that I have showed up myself pretty bad :(
J.
Christopher Benson-Manica wrote: ja***********@seznam.cz <ja***********@seznam.cz> wrote:
Hello, I'm new to c - so sorry if this is off topic here, please advice at least where should i ask... ;)
It isn't very topical; comp.unix.programmer is a good place to go (assuming, perhaps incorrectly, that you are using a flavor of Unix). You managed not to be totally off-topic, however...
Thank you ;)
Don't do it like that.
while( (ch=getc(stdin)) != EOF ) { putc( ch, stdout ); }
Thank you for kind reply, I screwed "copy and paste" operation :(
The piece of program I pasted here was wrong, original of my program is
longer and it was not point to bore anyone with that, when that worked.
My loop is working... my only mistake was I forgot to leave fgetc inside
loop - in original it's there of course... :)
J.
Barry wrote: <ja***********@seznam.cz> wrote in message news:43********@x-privat.org...
Hello, I'm new to c - so sorry if this is off topic here, please advice at least where should i ask... ;)
I have a program in c which is working fine, it reads everything from pipe, modifies output data a bit and writes to stdout.
When it is executed without parameters, program works fine. But what if I'd like to pass some extra configuration parameters to my program?
1. c:\> pipetest < file_in > file_out // this works 2. c:\> pipetest /parameter < file_in // also works, writes file_in and parameters to stdout 3. c:\> pipetest /parameter < file_in > file_out // nothing happens !?
Thanks anyone for kind advice and a nice day to all, Y.
// pitest.c #include <stdio.h> #include <fcntl.h> #include <io.h>
int main(int argc,char *argv[]) { int ch,i; for (i = 1; i < argc; i++) { printf("%s\n",argv[i]); } setmode(fileno(stdin), O_BINARY); setmode(fileno(stdout), O_BINARY); ch=getc(stdin); while (!feof(stdin)) { putc(ch,stdout); } } // -------
Shouldn't the getc() call be inside the while loop?
Of course it should, sorry :( The piece of program I pasted here was
wrong, original of my program is longer and it was not point to bore
anyone with that, when that worked. My loop is working... my only
mistake was I forgot to leave fgetc inside loop - in original it's there
of course... :)
I was confused with the pipes and one guy already found the reply :)
J. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: jenny |
last post by:
Hi,
I have a java socket program running on AIX 4.3.3.0 platform. It
opens a socket and sends data to our customer over a leased fractional
T1 line. The line is always connected. However,...
|
by: Rajarshi Guha |
last post by:
Hi,
I'm having a little trouble when I read from a named pipe. I create a
pipe by
os.mkfifo('/tmp/mypipe')
and then open it for reading with
fin = open('/tmp/mypipe','r+')
|
by: Hoegje |
last post by:
I am writing a C++ program, which should create a sub- process to
start a telnet session to another server. Then it should login to that
server (on the telnet login) and execute one or more...
|
by: j. del |
last post by:
I am just beginning to write programs... and my first task that I have
set myself is to write a little program that will generate cryptic
bywords from a source of text. A cryptic byword is...
|
by: Greg |
last post by:
I am trying to implement the UNIX pipe command using C but with the
"->" operator. Everything works fine with 1 pipe, but when I try to
use 2 or more, it hangs up when reading the pipe_in...
| |
by: Steve R. Hastings |
last post by:
While studying iterators and generator expressions, I started wishing I
had some tools for processing the values. I wanted to be able to chain
together a set of functions, sort of like the...
|
by: Igna |
last post by:
Hello. I have to write a pipe to joint a GUI in perl and a simulation
program in c. I have read all the docs found in perl.com and now I am
trying to make a test with this simple program if it is...
|
by: 7stud |
last post by:
Hi,
Can someone explain what a broken pipe is? The following produces a
broken pipe error:
----------
import subprocess as sub
p = sub.Popen(, stdin=sub.PIPE, stdout=sub.PIPE)
|
by: dgk |
last post by:
I trying to use a named pipe but can't figure out how to get the
callback to work:
Module Module1
Private ps As System.IO.Pipes.NamedPipeServerStream
Public Sub main()...
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
|
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: 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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |