473,394 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How can I write a program supports pipe in command line

11
As we know, the following command will print all the .txt files in current directory.
Expand|Select|Wrap|Line Numbers
  1. echo /b | findstr "\.txt$"
I want write a program called "my_findstr.exe" just do the same thing as above using command:
Expand|Select|Wrap|Line Numbers
  1. echo /b | my_findstr "\.txt$"
Is it possible?
Oct 28 '07 #1
5 1145
sinbao
11
Sorry, I made a mistake where "echo /b" should be "dir /b" :(
Oct 28 '07 #2
kenobewan
4,871 Expert 4TB
Which language are you working with? More info please. Thanks.
Oct 28 '07 #3
sinbao
11
Which language are you working with? More info please. Thanks.
C# for example, I will write code like this:

Expand|Select|Wrap|Line Numbers
  1. namespace my_findstr
  2. {
  3.     class Program
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             if(args.Length > 0)
  8.             {
  9.                 string matchStr = args[0];
  10.                 string input = "here is the input string, but where can I get it from the pipe operation?";
  11.                 Match m = Regex.Match(input, matchStr);
  12.                 if(m.Success)
  13.                 {
  14.                     Console.WriteLine(input);
  15.                 }
  16.             }
  17.         }
  18.     }
Oct 28 '07 #4
Plater
7,872 Expert 4TB
Pipe redirection is not related to program specifically.
All pipe "|" (and also "<" ">") do is change the streams of StandardInput and StandardOutput.
If your program uses Console.Read()/Write() then the pipe and redirections will have an effect on your program.

So doing this:
Expand|Select|Wrap|Line Numbers
  1. dir/s > myprog.exe
  2.  
Would fill up the StandardIn stream of you program with the output of "dir/s"
(Use Console.ReadLine() to get it line by line)
Oct 29 '07 #5
sinbao
11
Pipe redirection is not related to program specifically.
All pipe "|" (and also "<" ">") do is change the streams of StandardInput and StandardOutput.
If your program uses Console.Read()/Write() then the pipe and redirections will have an effect on your program.

So doing this:
Expand|Select|Wrap|Line Numbers
  1. dir/s > myprog.exe
  2.  
Would fill up the StandardIn stream of you program with the output of "dir/s"
(Use Console.ReadLine() to get it line by line)
thanks, that's what I want!
Oct 30 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: rinkworks | last post by:
I'm having trouble with Popen4 locking up on me. It appears to be unrelated to the actual command I'm running, because I made the command just "cat" (I'm on UNIX) to echo whatever input I sent it,...
13
by: Pie | last post by:
I like to have my program (running on my home machine) email me (wherever I am) whenever it reaches a certain mile-stone (finishes a phase of the simulation or runs into an interesting path in the...
18
by: jas | last post by:
Hi, I would like to start a new process and be able to read/write from/to it. I have tried things like... import subprocess as sp p = sp.Popen("cmd.exe", stdout=sp.PIPE)...
2
by: Ben Chivers | last post by:
I have a problem, which I think can be easily solved somehow. I am trying to execute a C program through using a PHP script. I do this by sending an exec command from the PHP script. My PHP...
18
by: utab | last post by:
Dear all, I am making a system call to the well known Gnuplot with system("gnuplot"); gnuplot opens if I only supply this command but I would like to pipe that command line in my C++...
3
by: Reggie | last post by:
I am writing a c++ program that will run multiple *.exe files and dump the results to a file. In my test case, I am using netstat. I am running netstat from my c++ program with the ...
14
by: cage | last post by:
hello can i write a eof to a file descriptor without closing it? like: fd.write(EOF) or something grts, ruben
1
by: NeoGregorian | last post by:
Hello, I am writing a wrapper to a basic Input/Output programs (where you type a one line command at a time and then get 0 or more lines of output before you can input the next command). I'm...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.