pipe output from c program to a korn shell script

pipe output from c program to a korn shell script

Post by luke_ai.. » Fri, 07 Jul 2000 04:00:00



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

Quote:}

---------------------------------
#!/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.

 
 
 

pipe output from c program to a korn shell script

Post by Arthur H. Gol » Sat, 08 Jul 2000 04:00:00



> 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.

I don't see what you're trying to pipe (you never write anything to
stdout, and your script never reads anything). In fact, you're _already_
doing everything you want (i.e. building the command, including the
password obtained, and running the script via system()) in the code
you've posted.

HTH,
--ag

--
Artie Gold, Austin, TX  (finger the cs.utexas.edu account for more info)

--
"I'd sooner fly another combat mission than ride the Cyclone again" --
Joseph Heller

 
 
 

pipe output from c program to a korn shell script

Post by Chris F.A. Johns » Sat, 08 Jul 2000 04:00:00


: 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: ");

   printf("%s\n", pw);

/*
:  sprintf(cmdline,"use_password.ksh %s",pw);
:  system(cmdline);
*/
    return 0;
: }
: ---------------------------------
: #!/bin/ksh
: # use_password.ksh
: print $1
: ---------------------------------
: $ hide_password | use_password.ksh

use_password.ksh `hide_password`

Your script does not read from stdin; it uses a command line argument.

or do this to read from stdin:

#!/bin/ksh
# use_password.ksh
read p
echo $p

$ 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.
--
        Chris F.A. Johnson

        -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
               Everything in moderation - including moderation  

 
 
 

1. typeset -f gives funny output when executed from Korn shell script

I just discovered a funny behaviour of the typeset -f command when
executed in a shell script.

Assume function a is defined in your ENV file (.kshrc)

---------- begin .kshrc
function a {
        : # this is function a
---------- end .kshrc

and file foo contains the following lines

---------- begin foo
function b {
        : # this is function b

typeset -f
---------- end foo

Sourcing foo gives the following output

---------- begin output of ". foo"
function a
{
        : # this is function a
function b
{
        : # this is function b
---------- end output of ". foo"

while executing foo gives

---------- begin output of "foo"
function a
{
<command unknown>
function b
---------- end output of "foo"

and, as you might (not) expect :

---------- begin output of "ksh foo"
function a
function b
---------- end output of "ksh foo"

Is this typycal to my implementation of the Korn shell (HP 9000/400,
HP-UX 8.0) or is it a
        - ksh bug,
        - ksh undocumented feature,
        - ksh documented feature well hidden in TFM?

Marc.
--
Marc PHILIPS                    Eurocontrol - Central Flow Management Unit

Tel: +32 2 729 33 09            B-1040 BRUXELLES
Fax: +32 2 729 32 16            Belgium

2. too many open files on Solaris2.4?

3. Convert Bash shell script to Korn shell script

4. Displaying Actual Connect Speed?

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

6. hdparm-2.3

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

8. pipe c output to shell script

9. Calling a Korn Shell script from a C-program

10. Korn shell script/program

11. Korn shell script programming problem

12. best korn shell resources and is there a korn shell faq