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?
how to pass stdout text as command input to another program?
Moderator: DosItHelp
Re: how to pass stdout text as command input to another prog
Someone else may reply, but I'd like to see an actual problem so you can get the most appropriate solution.
Re: how to pass stdout text as command input to another prog
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());
}
}
Re: how to pass stdout text as command input to another prog
It would seem that you're not talking about batch scripting, which is currently the primary focus of Dostips.
Re: how to pass stdout text as command input to another prog
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