pipe c output to shell script

pipe c output to shell script

Post by Jeffrey Fulme » Wed, 17 Dec 1997 04:00:00



Hello,
I'm having a little trouble with this:
How do I pipe output from a c program to a shell script.  I wrote a c
program to calculate dates and I want to then pipe that output to a
shell script.

# chgdate -30 | shellscript

in the shell script I tried to use the $1 var for the chgdate output.
the script throws an error
[: =: unary operator expected

Any help would be appreciated..

Jeff

 
 
 

pipe c output to shell script

Post by J. Wakeley Purp » Sat, 20 Dec 1997 04:00:00


I think what you want is:

        shellscript `chgdate -30`

This will run the chgdate program and present its output as the command
line args to shellscript as $1.

If you want to do it your way you would have to do

        read chgdate_output

first thing to read the standard input piped from the chgdate program.


>Hello,
>I'm having a little trouble with this:
>How do I pipe output from a c program to a shell script.  I wrote a c
>program to calculate dates and I want to then pipe that output to a
>shell script.

># chgdate -30 | shellscript

>in the shell script I tried to use the $1 var for the chgdate output.
>the script throws an error
>[: =: unary operator expected

>Any help would be appreciated..

>Jeff

--



 
 
 

pipe c output to shell script

Post by Dr. » Mon, 22 Dec 1997 04:00:00


: Hello,
: I'm having a little trouble with this:
: How do I pipe output from a c program to a shell script.  I wrote a c
: program to calculate dates and I want to then pipe that output to a
: shell script.

: # chgdate -30 | shellscript

: in the shell script I tried to use the $1 var for the chgdate output.
: the script throws an error
: [: =: unary operator expected

Sounds like your shell script has a problem mon. Post the script and/or

It's most likely a problem with one of your 'if' statemnets.

Stephen

 
 
 

pipe c output to shell script

Post by Grigoriy Stroki » Tue, 23 Dec 1997 04:00:00


Quote:>: # chgdate -30 | shellscript

>: in the shell script I tried to use the $1 var for the chgdate output.
>: the script throws an error
>: [: =: unary operator expected

"$1" means first program argument, not the standard output.
You can either make chgdate's output to be the script's first argument (and
then use $1):
  shellscript "$(chgdate -30)"
Or, if you use a pipe "cghdate -30 | shellscript", read the standard output
using read command, e.g.
read a; echo "my program has written $a" # ...some actions with $a

Grigoriy Strokin

 
 
 

1. pipe output from c program to a korn shell script

From the UNIX command line I would like to prompt the user for a
password using getpass (to hide the password) and then pipe the
password to a korn shell script.

Here is what I have tried so far:

#include <stdlib.h>
/* hide_password.c */

int main(argc, argv)
int argc;
char *argv[];
{
 char *pw;
 char cmdline[128];
 pw = getpass("Password: ");
 sprintf(cmdline,"use_password.ksh %s",pw);
 system(cmdline);
---------------------------------
#!/bin/ksh
# use_password.ksh
print $1
---------------------------------
$ hide_password | use_password.ksh
Password:

Broken Pipe
$
---------------------------------

Can anyone help me with this?

Thanks

Sent via Deja.com http://www.deja.com/
Before you buy.

2. Zip Drive

3. Piping output to a C-shell script from another command - HOW?

4. XF86Setup and Logitech Trackman

5. Incomplete output from crontab email: running shell scripts from a perl script

6. Unix - Frequently Asked Questions (Contents) [Frequent posting]

7. Shell script to run script to record output from a program

8. Problem on TCP connect time?

9. Do any shells support multiple input pipes (diff of output of two processes) ?

10. CERN Error 500: can't read script output pipe

11. Piping output from background tasks to TCL scripts under Solaris 2.5.x

12. Why Does Piping Output to an Executable Change the Way it Outputs?

13. a question about 'read' from pipe in shell script