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 1097977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:30:41+00:00 2026-05-17T00:30:41+00:00

How to make this work on windows , the file filename.txt is not being

  • 0

How to make this work on windows , the file filename.txt is not being created.

Process p = Runtime.getRuntime().exec("cmd echo name > filename.txt");

Clearly the expected output is a “filename.txt” should be created (C:\Documents and Settings\username\filename.txt ) with the content “name”.


Was able to manage with the following code , even though the file was”filename.txt” is not being created with processBuilder

       Runtime runtime = Runtime.getRuntime();
       Process process = runtime.exec("cmd /c cleartool lsview");
       // Directly to file

//Process p = Runtime.getRuntime().exec( 
//              new String[] { "cmd", "/c", "cleartool lsview > filename.txt" },null, new File("C:/Documents and Settings/username/")); 

       InputStream is = process.getInputStream();
       InputStreamReader isr = new InputStreamReader(is);
       BufferedReader br = new BufferedReader(isr);
       String line;

       System.out.printf("Output of running %s is:", 
           Arrays.toString(args));

       while ((line = br.readLine()) != null) {
         System.out.println(line);
       }

OR , using ProceessBuilder ,

Process process = new ProcessBuilder( "cmd", "/c", "cleartool lsview" ).start();
InputStream is = process.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));

System.out.printf("Output of running %s is:", Arrays.toString(args));

String line;
while ((line = br.readLine()) != null) {
    System.out.println(line);
}
  • 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-05-17T00:30:42+00:00Added an answer on May 17, 2026 at 12:30 am

    You should actually be using ProcessBuilder instead of Runtime.exec (see the docs).

    ProcessBuilder pb = new ProcessBuilder("your_command", "arg1", "arg2");
    pb.directory(new File("C:/Documents and Settings/username/"));
    
    OutputStream out = new FileOutputStream("filename.txt");
    InputStream in = pb.start().getInputStream();
    
    byte[] buf = new byte[1024];
    int len;
    while ((len = in.read(buf)) > 0)
        out.write(buf, 0, len);
    
    out.close();
    

    (I’d adapt it to cmd and echo if I had a windows-machine in reach… Feel free to edit this post!)

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

Sidebar

Related Questions

Not sure exactly what I need to do to make this work, so my
I need to make this function work everywhere, except IE6-7 $(function(){ window.scrollTo(0,300); }) Please
how can I make this work? $current_id=5; SELECT Id FROM table1 WHERE Output='yes' and
Is there any way to make this work in Java? public static void change(List<?
I have this code and I need to make this work: if ($handle =
How on earth do I make this work? I have a database with 3
I have been pulling my hair out trying to make this work. I have
Or, in other words, how to make this work: function foo(){} //do something that
How can I make this code work? #!/bin/bash ARRAYNAME='FRUITS' FRUITS=( APPLE BANANA ORANGE )
How do you make this code work? Just have pyglet installed and change fireball.png

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.