LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-30-2014, 08:22 PM   #1
pnorris1231
LQ Newbie
 
Registered: Apr 2014
Posts: 7

Rep: Reputation: Disabled
Need help with running a script using inputs and outputs


Hi,

I have a script called ./assign3.exe , when run it asks for the length and width of a rectangle. I have created a file named "in file" to have the following contents : 30.0 40.0 . This file predefines length and width. when I run it I get the following : (which is correct), but what I need to do is write the output to a file called outfile. - How do I do this using the script below?

Thanks!

plnorris@CIS606:~$ ./assign3.exe < infile

Program to calculate the area of a rectangle
Please Enter the Length:
Please Enter the Width:
Length= 30.000000 Width= 40.000000 Area= 1200.000000
 
Old 04-30-2014, 08:25 PM   #2
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 2,412

Rep: Reputation: Disabled
You could simply redirect the output with >.
 
Old 04-30-2014, 08:41 PM   #3
pnorris1231
LQ Newbie
 
Registered: Apr 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
I tried that and do not think it wrote anything to the output file (out file)

plnorris@CIS606:~$ ./assign3.exe < infile > outfile
plnorris@CIS606:~$ ls outfile
outfile
plnorris@CIS606:~$
 
Old 04-30-2014, 08:55 PM   #4
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 2,412

Rep: Reputation: Disabled
ls only shows the directory listing, which confirms the file is there. Try cat outfile to see what it contains.
 
Old 04-30-2014, 08:59 PM   #5
pnorris1231
LQ Newbie
 
Registered: Apr 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
looks like it does not contain anything. Just to confirm i ran cat in file as well..

plnorris@CIS606:~$ cat outfile
plnorris@CIS606:~$ cat infile

Program to calculate the area of a rectangle
Please Enter the Length:
Please Enter the Width:
Length= 0.000000 Width= 0.000000 Area= 0.000000
plnorris@CIS606:~$
 
Old 04-30-2014, 09:01 PM   #6
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 2,412

Rep: Reputation: Disabled
Looks like you somehow got the filenames (or the redirect symbols) mixed up, as "infile" seems to contain the output from the script.
 
Old 04-30-2014, 09:04 PM   #7
pnorris1231
LQ Newbie
 
Registered: Apr 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
here is what I am trying to accomplish :

1. create a file named in file that contains the numbers 30.0 and 40.0

2. execute the ./assign3.exe program with its input coming from the in file ( meaning the program asks for length and width) and the output going to a file called out file.

---------- Post added 04-30-14 at 10:04 PM ----------

sorry create a file named infile
 
Old 04-30-2014, 09:10 PM   #8
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 2,412

Rep: Reputation: Disabled
Running the script with stdin and stdout redirected will do that:
Code:
./assign3.exe < infile > outfile
You can also perform the redirection inside the script. In that case, use > to write the first line to "outfile" (it will overwrite the file if it exists), and then use >> if you wish to add further data to the file:
Code:
echo Length= $foo Width= $bar Area= $baz > outfile
echo ...more text... >> outfile
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] passing multiple inputs to script that calls other script(s) glamiss Linux - General 3 05-02-2012 01:32 AM
[SOLVED] Passing inputs to the script senthil1186 Linux - Server 2 08-30-2011 02:15 PM
Real time management of audio inputs/outputs? Jeff91 Linux - Software 9 06-23-2010 03:05 PM
Is this possible to record inputs which will be provided during running script gangadhar_m Linux - Server 10 02-23-2010 03:10 AM
shell script inputs aloishis89 Programming 3 03-10-2008 02:23 AM


All times are GMT -5. The time now is 08:24 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration