LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-29-2006, 02:22 PM   #1
aznium
Member
 
Registered: Jun 2005
Posts: 36

Rep: Reputation: 15
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
 
Old 08-29-2006, 03:02 PM   #2
patrickvk
LQ Newbie
 
Registered: Jun 2006
Posts: 5

Rep: Reputation: 0
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
 
Old 08-29-2006, 03:04 PM   #3
demon_vox
Member
 
Registered: May 2006
Location: Argentina
Distribution: SuSE 10
Posts: 173

Rep: Reputation: 30
echo "yourName" | dummyprogram
 
Old 08-29-2006, 03:15 PM   #4
aznium
Member
 
Registered: Jun 2005
Posts: 36

Original Poster
Rep: Reputation: 15
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
 
Old 08-29-2006, 03:18 PM   #5
aznium
Member
 
Registered: Jun 2005
Posts: 36

Original Poster
Rep: Reputation: 15
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");
 
Old 08-30-2006, 12:34 AM   #6
aznium
Member
 
Registered: Jun 2005
Posts: 36

Original Poster
Rep: Reputation: 15
any tips please?
 
Old 08-31-2006, 10:30 AM   #7
demon_vox
Member
 
Registered: May 2006
Location: Argentina
Distribution: SuSE 10
Posts: 173

Rep: Reputation: 30
echo -e "firstinput\nsecondInput\n" | ./dummyprogram
 
Old 08-31-2006, 12:24 PM   #8
KenJackson
Member
 
Registered: Jul 2006
Location: Maryland, USA
Distribution: Fedora and others
Posts: 757

Rep: Reputation: 145Reputation: 145
Code:
#!/bin/sh
echo -n "Enter first name: "
read first
echo -n "Enter last name: "
read last

echo "You claim to be $first $last"
 
Old 08-31-2006, 12:39 PM   #9
aznium
Member
 
Registered: Jun 2005
Posts: 36

Original Poster
Rep: Reputation: 15
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
 
Old 09-02-2006, 07:58 PM   #10
aznium
Member
 
Registered: Jun 2005
Posts: 36

Original Poster
Rep: Reputation: 15
any help guys? please . thanks.
 
Old 09-02-2006, 08:12 PM   #11
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
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.
 
Old 09-02-2006, 08:13 PM   #12
aznium
Member
 
Registered: Jun 2005
Posts: 36

Original Poster
Rep: Reputation: 15
ahhh i see

im running debian linux

so i should keep trying expect?
 
Old 09-02-2006, 08:24 PM   #13
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
check the man page of your passwd program whether there's a --stdin option. Think you can give it a try if there is.
 
Old 09-02-2006, 08:36 PM   #14
aznium
Member
 
Registered: Jun 2005
Posts: 36

Original Poster
Rep: Reputation: 15
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
 
Old 09-02-2006, 09:19 PM   #15
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
No need to use C, I told you you can use expect.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
scripting kb100 Programming 16 08-17-2006 06:41 AM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 04:29 AM
Scripting CICA Linux - General 7 10-03-2005 10:36 AM
Need some scripting help Askari Programming 1 11-26-2003 10:25 AM
scripting help wedgeworth Linux - Software 10 09-25-2003 01:57 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration