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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:57:11+00:00 2026-05-31T20:57:11+00:00

I want to call shell script on windows environment using java code. I am

  • 0

I want to call shell script on windows environment using java code.
I am trying to execute code below to run my test script(not actual script):

Java Code:

public static void main (String args[]) {
        Runtime r = Runtime.getRuntime();
        try {
            Process p = r.exec("C:\\cygwin\\bin\\bash -c '/cygdrive/d/scripts/test.sh'");
            InputStream in = p.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            System.out.println("OUT:");
            String line;
            while ((line = br.readLine()) != null) {
                System.out.println(line);
            }

            in = p.getErrorStream();
            br = new BufferedReader(new InputStreamReader(in));
            System.out.println("ERR:");
            while ((line = br.readLine()) != null) {
                System.out.println(line);
            }

            p.waitFor();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

test.sh

#!/bin/bash

rm -rf ./test

But I am getting these error and script in not able to remove the directory.

ERR:
/cygdrive/d/ereader/scripts/test.sh: line 2: $’\r’: command not found
/cygdrive/d/ereader/scripts/test.sh: line 3: rm: command not found

Another thing, when I run the script from the cygwin terminal it works fine. I checked the path variable they all are fine. But I try to execute same script through java code it gives error..

Now how to tell java program where to refer for rm commands?

  • 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-31T20:57:12+00:00Added an answer on May 31, 2026 at 8:57 pm

    probably you will need to set the PATH variable first thing in the test.sh script. Make sure rm is in the PATH you set

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

Sidebar

Related Questions

I want to run a shell script in php, but this shell script takes
I am trying to call my linux executable from shell script. Before calling this
I want to source a shell script from within Perl and have the environment
I want to run a python script without explicitly having to call python every
I'm trying to call a custom shell script through sh : /bin/sh -c 'myscript.sh`
I've run into a really silly problem with a Linux shell script. I want
I want to use a shell script that I can call to set some
My $SHELL is tcsh. I want to run a C shell script that will
From a C program I want to call a shell script with a filename
I want to call external application from shell script, but this shell script gets

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.