• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

read stdout of a commandline prog

 
Greenhorn
Posts: 1
Firefox Browser Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For example, if I do this:

How to get the java prog to read these lines?
 
Ranch Hand
Posts: 441
Scala IntelliJ IDE Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm by no means an expert on this, and it's probably not the best way, but how about getting your command line prog to call "java MyClass foo\nbar\nbaz" then deal with them as command line arguments?
 
Marshal
Posts: 27534
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You pipe them to the stdin of your Java class:

and write your class to read the data from System.in.
 
Saloon Keeper
Posts: 14697
331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, this is more OS specific, and not really Java related. Assuming you are using Unix, in Windows you can pipe commands using | as well.
 
Ranch Hand
Posts: 257
Hibernate Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Below class reads the input from standard input stream. Please let me know if it is not what you are looking for ...




Test:
echo 'Hello' | java -cp . com.test.CmdTest

Result:
Reading data ....
'Hello'
 
Marshal
Posts: 77245
371
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

This question is too difficult for "beginning" so I shall move it.
 
reply
    Bookmark Topic Watch Topic
  • New Topic