LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Scripting (https://www.linuxquestions.org/questions/programming-9/scripting-478507/)

aznium 08-29-2006 02:22 PM

Scripting
 
How do i send input to program?

such as i call

dummyprogram

and it outputs

enter dummyname:


how would i send a name into the prorgam?

thanks

patrickvk 08-29-2006 03:02 PM

Please, be more specific.

What do you really want? Do you want to write your own C program which gets user's input,
Or a bash script, or do you just want to redirect something from the terminal to a program (using a |)...?

thanks

demon_vox 08-29-2006 03:04 PM

echo "yourName" | dummyprogram

aznium 08-29-2006 03:15 PM

basically im calling an program that accepts two inputs

such as

./dummy
output: enter dummy first name
output: enter dummy last name

.

i want to write a script to do that for me

what i got so far

#!/usr/bin/expect --

spawn calldummy -someoptions
expect "*"
send "firstname\r"
expect "*"
send "lastname\r"

but the stuff doesnt seem to pass through properly

thanks

aznium 08-29-2006 03:18 PM

it would be even better if i can do it in c

if it was in C, something like this doesnt work for me

system("dummy -options");
system("firstname");
system("lastname");

aznium 08-30-2006 12:34 AM

any tips please?

demon_vox 08-31-2006 10:30 AM

echo -e "firstinput\nsecondInput\n" | ./dummyprogram

KenJackson 08-31-2006 12:24 PM

Code:

#!/bin/sh
echo -n "Enter first name: "
read first
echo -n "Enter last name: "
read last

echo "You claim to be $first $last"


aznium 08-31-2006 12:39 PM

echo -e "firstinput\nsecondInput\n" | ./dummyprogram

isnt working

i tried /r and /r/n

the program i am running is passwd . as in "passwd username"

im getting a password do not match . but i ebelieve the input goes through

any tips

thanks so far

aznium 09-02-2006 07:58 PM

any help guys? please . thanks.

jlliagre 09-02-2006 08:12 PM

Quote:

Originally Posted by aznium
the program i am running is passwd

And you think that piece of information wasn't deserving to be mentioned sooner ?

Depending the O/S you are running, and you failed to mention that too, passwd is picky about from where its input is coming.

However, expect is handling passwd properly so you should keep on searching that way.

aznium 09-02-2006 08:13 PM

ahhh i see

im running debian linux

so i should keep trying expect?

ghostdog74 09-02-2006 08:24 PM

check the man page of your passwd program whether there's a --stdin option. Think you can give it a try if there is.

aznium 09-02-2006 08:36 PM

i have no --stdin option

is it possible somehow to do it in C then? call the passwd and change the password?

i can of course write directly to /etc/passwd and /etc/shadow but i want to avoid that and use the passwd command if possible

jlliagre 09-02-2006 09:19 PM

No need to use C, I told you you can use expect.


All times are GMT -5. The time now is 06:45 PM.