Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / April 2008

Tip: Looking for answers? Try searching our database.

redirection operator compatible console application

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
muquaddim@gmail.com - 05 Apr 2008 16:53 GMT
Hi,
I have a program prog.exe. which takes IP as input its owner
information as output.
if input.txt contains,
xx.xx.xx.xx
yy.yy.yy.yy
zz.zz.zz.zz

now see how it works.

c:\> prog.exe xx.xx.xx.xx yy.yy.yy.yy > output.txt

it generates output.txt with contact info for each ip.

if I don't pass any command line argument it takes input from stdin.
c:\> prog.exe
xx.xx.xx.xx // my input
xx@abc.com // contact info
yy.yy.yy.yy  // my input
yy@efg.net  // contact info

to break the program I have to press Ctrl+C

Now if I use input redirection operator
c:\> prog.exe  < input.txt
xx@abc.com
yy@efg.net
zz@hij.org

In this point my program waits for standard input too.
I want my program should process all the input and output the data
then exit. no wait.

For this problem I can not run the following command,

C:\> prog.exe < input.txt > output.txt

I never know whether the program has ended.

The simple Code can be found in http://nopaste.info/31b391011b.html

Please give me a solution.

Thanks in Advance.
Lasse Vågsæther Karlsen - 05 Apr 2008 17:08 GMT
> Hi,
> I have a program prog.exe. which takes IP as input its owner
> information as output.
> if input.txt contains,
<snip>
> Now if I use input redirection operator
> c:\> prog.exe  < input.txt
[quoted text clipped - 5 lines]
> I want my program should process all the input and output the data
> then exit. no wait.

The way your program is built, it should exit out of the loop when it
hits the end of the data.

The correct way to end the program is to hit Ctrl+Z when you're giving
it text from the console.

When you give it text from a file, or from a different program, it
should terminate by its own.

However, you haven't shown what "startProcess" does, so there could be
other things that holds your program up.

Try the following simple program and see if it behaves as you expect:

using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(String[] args)
        {
            while (true)
            {
                String s = Console.In.ReadLine();
                if (s == null)
                    break;
                Console.Out.WriteLine(s);
            }
        }
    }
}

Signature

Lasse Vågsæther Karlsen
mailto:lasse@vkarlsen.no
http://presentationmode.blogspot.com/
PGP KeyID: 0xBCDEA2E3

muquaddim@gmail.com - 05 Apr 2008 18:36 GMT
> muquad...@gmail.com wrote:
> > Hi,
[quoted text clipped - 50 lines]
> mailto:la...@vkarlsen.nohttp://presentationmode.blogspot.com/
> PGP KeyID: 0xBCDEA2E3

Thanks Lasse.
I didnt see your solution as I didn't refresh the page.
Whatever thanks again
muquaddim@gmail.com - 05 Apr 2008 17:32 GMT
On Apr 5, 10:53 am, "muquad...@gmail.com" <muquad...@gmail.com> wrote:
> Hi,
> I have a program prog.exe. which takes IP as input its owner
[quoted text clipped - 40 lines]
>
> Thanks in Advance.

its solved

while((ip=Console.ReadLine())!=null){
process(ip);
}

so easy

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.