redirection operator compatible console application

  • Thread starter Thread starter muquaddim
  • Start date Start date
M

muquaddim

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
(e-mail address removed) // contact info
yy.yy.yy.yy // my input
(e-mail address removed) // contact info

to break the program I have to press Ctrl+C

Now if I use input redirection operator
c:\> prog.exe < input.txt
(e-mail address removed)
(e-mail address removed)
(e-mail address removed)

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.
 
Hi,
I have a program prog.exe. which takes IP as input its owner
information as output.
if input.txt contains,
Now if I use input redirection operator
c:\> prog.exe < input.txt
(e-mail address removed)
(e-mail address removed)
(e-mail address removed)

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.

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);
}
}
}
}
 
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
(e-mail address removed) // contact info
yy.yy.yy.yy // my input
(e-mail address removed) // contact info

to break the program I have to press Ctrl+C

Now if I use input redirection operator
c:\> prog.exe < input.txt
(e-mail address removed)
(e-mail address removed)
(e-mail address removed)

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 inhttp://nopaste.info/31b391011b.html

Please give me a solution.

Thanks in Advance.

its solved

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

so easy
 
Hi,
I have a program prog.exe. which takes IP as input its owner
information as output.
if input.txt contains,
Now if I use input redirection operator
c:\> prog.exe < input.txt
(e-mail address removed)
(e-mail address removed)
(e-mail address removed)
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.

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

}

Thanks Lasse.
I didnt see your solution as I didn't refresh the page.
Whatever thanks again
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top