Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7824689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:41:12+00:00 2026-06-02T08:41:12+00:00

i need to know if a specific string is contained in a list of

  • 0

i need to know if a specific string is contained in a list of files. The list of files is dynamic and i have to check a dynamic list of strings. This must be done in Java to work with the result (true or false). And MS Windows is also a requirement.

I thought about that problem i tried to use the unix way to do this:

find C:/temp | xargs grep import -sl

With GnuWin this works in cmd without any problems. So i tried to convert this into Java language. I read many articles about using Runtime class and ProcessBuilder class. But none of the tips are working. At last i tried the following two code snippets:

String binDir = "C:/develop/binaries/";

List<String> command = new ArrayList<String>();
command.add("cmd");
command.add("/c");
command.add(binDir+"find");
command.add("|");
command.add(binDir+"xargs");
command.add(binDir+"grep");
command.add("import");
command.add("-sl");

ProcessBuilder builder = new ProcessBuilder(command);
builder.directory(new File("C:/temp"));
final Process proc = builder.start();

printToConsole(proc.getErrorStream());
printToConsole(proc.getInputStream());

int exitVal = proc.waitFor();

and

String binDir = "C:/develop/binaries/";
String strDir = "C:/temp/";

String[] command = {"cmd.exe ", "/C ", binDir + "find.exe " + strDir + " | " + binDir + "xargs.exe " + binDir + "grep.exe import -sl" };

Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec(command);

printToConsole(proc.getErrorStream());
printToConsole(proc.getInputStream());

int exitVal = proc.waitFor();

I also tried many other ways to concat the command, but either I get an error message (eg. file not found) or the process never comes back.

My questions:
1. Do you know a better way to do this job?
2. If not: Do you see any error in the code?
3. If not: Do you have another way i should try to run that command?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T08:41:13+00:00Added an answer on June 2, 2026 at 8:41 am

    Java’s support for subprocesses is pretty weak, especially on Windows. Avoid using that API if you don’t really need to.

    Instead, this SO question discusses how to replace the find for the recursive search, and the grep should be easy enough (especially with FileUtil.readLines(…) to help).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to build a dynamic connection string as shown in this tutorial :
I have a string buffer of about 2000 characters and need to check the
Need to know this so that i could send DTMF and that is going
Need to know which event triggered after text selection done in Apple iPad. It
I need to know if all the client-side validator checks have succeeded, or if
this is a very specific question, but i also have very specific details on
Parsing an array of string commands, I need to know if a string contains
I am trying to tokenize a string but I need to know exactly when
I need to parse a lot of html files in order to know which
Just a quick regex question...hopefully I have a string that looks something like this:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.