473,507 Members | 2,374 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pipe with program arguments does not work?

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);
}
}
// -------

Nov 15 '05 #1
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?
Nov 15 '05 #2
"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.
Nov 15 '05 #3
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.
Nov 15 '05 #4
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.
Nov 15 '05 #5
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.
Nov 15 '05 #6
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.
Nov 15 '05 #7
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.
Nov 15 '05 #8

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

Similar topics

1
27249
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,...
4
7443
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+')
2
4340
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...
13
4039
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...
7
3691
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...
2
1659
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...
2
3664
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...
11
21169
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)
1
5518
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()...
0
7223
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
7111
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
7319
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,...
0
7376
jinu1996
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...
1
7031
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
7485
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
3191
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...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
412
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...

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.