how to pass stdout text as command input to another program?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jsmith
Posts: 2
Joined: 12 May 2014 23:24

how to pass stdout text as command input to another program?

#1 Post by jsmith » 12 May 2014 23:33

I apologize for what I'm sure to most of you will seem like a very noobish question, but

if A prints a line of text to stdout and B reads input text from stdin, then we can pass A's output to B as follows

A | B

now suppose that B expects its input to be provided in the form of command line arguments. ie:

B "this is the input"

in this case, what's a simple way to pass A's output to B?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: how to pass stdout text as command input to another prog

#2 Post by foxidrive » 13 May 2014 04:02

Someone else may reply, but I'd like to see an actual problem so you can get the most appropriate solution.

jsmith
Posts: 2
Joined: 12 May 2014 23:24

Re: how to pass stdout text as command input to another prog

#3 Post by jsmith » 13 May 2014 22:22

Code: Select all

class A
{
   public static void Main(String[] args)
   {
      Console.WriteLine("Hello World");
   }
}

class B
{
   public static void Main(String[] args)
   {
      //this is how B would pick up A's output if it were reading from stdin
      //String pipedInput = Console.ReadLine();
      //if (pipedInput != null)
      //   Console.WriteLine(pipedInput.ToUpperCase());

      //but because B expects input to be provided as a command line argument,
      //how do we pipe A's output into B's Main method?
      if (args != null && args.Length > 0)
         Console.WriteLine(args[0].ToUpperCase());
   }
}

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: how to pass stdout text as command input to another prog

#4 Post by foxidrive » 14 May 2014 20:37

It would seem that you're not talking about batch scripting, which is currently the primary focus of Dostips.

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: how to pass stdout text as command input to another prog

#5 Post by Aacini » 14 May 2014 22:47

jsmith wrote:if A prints a line of text to stdout and B reads input text from stdin, then we can pass A's output to B as follows

A | B

now suppose that B expects its input to be provided in the form of command line arguments. ie:

B "this is the input"

in this case, what's a simple way to pass A's output to B?


Code: Select all

for /F "delims=" %%a in ('A') do B "%%a"

Previous command execute A and then, with each output line from A, execute B passing the whole line as one argument enclosed in quotes.

If this is not what you want, please explain it more carefully...

Antonio

Post Reply