pipe with program arguments does not work?

J

jan.dostrasil

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);
}
setmode(fileno(stdin), O_BINARY);
setmode(fileno(stdout), O_BINARY);
ch=getc(stdin);
while (!feof(stdin)) {
putc(ch,stdout);
}
}
// -------
 
B

Barry

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);
}
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?
 
H

Hake

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);
}
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.
 
C

Christopher Benson-Manica

Hake said:
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.
 
C

Christopher Benson-Manica

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

jan.dostrasil

Hake said:
> >
>
>>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);
>> }
>> 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.
 
J

jan.dostrasil

Christopher said:
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.
 
J

jan.dostrasil

Barry said:
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);
}
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top