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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:50:42+00:00 2026-06-08T08:50:42+00:00

So I have a client and a server Java program. The client uses Java

  • 0

So I have a client and a server Java program. The client uses Java processbuilder to execute the script but my problem is that the user inputs information that needs to be passed to the bash script. So, essentially, I need to know how to send three different strings to three different variables that are being read by the bash script. This script is copying a file so I would rather not make a txt file with java and have the script read the file. I would also like a way for this to be able to run on OS X and Windows so improvements are welcome. I am using Java 7 on Ubuntu currently.

Here is a snippet of what I am trying to do:
.java

    Scanner bob = new Scanner(System.in);
    String workingDirectory = new String(System.getProperty("user.dir"));
    File tempDir = new File(workingDirectory); 
    String script = new String(workingDirectory + "/copyjava.sh");

    System.out.print("Designate the location of the file: ");
    String loc = bob.next();
    System.out.print("Type the name of the file w/ extension: ");
    String name = bob.next();
    System.out.print("What is the location of THIS file? "); //I know there is a way to do this automagically but I can't remember how...
    String wkspace = bob.next();
    ProcessBuilder pb = new ProcessBuilder( script, loc, name, wkspace);
    pb.start();
    File myFile = new File (name);

Script:

read loc

read name

read wkspace

cd $LOC

cp $name $wkspace
  • 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-08T08:50:47+00:00Added an answer on June 8, 2026 at 8:50 am

    There is a problem with your shell script. The read command reads from stdin, but you are passing the input as arguments. You are also changing the case of the loc variable. Variables in the shell are case sensitive. Change your script to the following:

    #!/bin/sh
    loc=$1
    name=$2
    wkspace=$3
    cd "$loc" || { printf 'failed to cd to %s\n' "$loc" ; exit 1; }
    cp "$name" "$wkspace" || { printf 'failed to copy %s\n' "$name" ; exit 1; }
    

    On a side note, you shouldn’t need to call an external script written in a different language just to copy a file. You should implement this in java. Implementing this in java will also give your code the platform independence you desire.

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

Sidebar

Related Questions

I have a java client program that uses mdns with service discovery to find
I have a Java program that mirrors a connection from a client server to
Ok, so I've got an Open Source Java client/server program that uses packets to
In my Java Sockets program, I have implemented a client-server Observer pattern. That is,
I have created a server in java which accepts client connections. But I am
I have a client/server program that attempts to send and receive an object. There
i have a java chat server & client, that works fine. I made a
I have a java program that acts as a POP3 client using javax.mail. I
I have created a Server, Client kind of program with RMI. But whenever I
Is this even possible? I have a java server program on a mac that

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.