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

  • Home
  • SEARCH
  • 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 3961158
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:56:29+00:00 2026-05-20T02:56:29+00:00

I have been developing a program lately that compiles and runs a C++ Program

  • 0

I have been developing a program lately that compiles and runs a C++ Program from a Java program, I have gotten everything working basically (or atleast to my knowledge) but then I noticed some things being printed to the Error Stream:

cdog5000@srv3:~$ java -Xmx50m -jar main2.jar
Running Command: sudo g++ --static -o "/home/cdog5000/cody.out" "/home/cdog5000/cody.cpp"
Err: g++: "/home/cdog5000/cody.cpp": No such file or directory
Err: g++: no input files


cdog5000@srv3:~$ ls -l
total 4548
-rwxr-xr-x 1 cdog5000 cdog5000 1297588 Feb  3 23:11 a.out
-rwxr-xr-x 1 cdog5000 cdog5000    7978 Feb  2 04:39 cody
-rw-r--r-- 1 cdog5000 cdog5000     106 Feb  4 02:09 cody.cpp
-rwxr-xr-x 1 cdog5000 cdog5000 1297357 Feb  4 02:09 cody.out
-rw-r--r-- 1 root     root      410433 Feb  4 02:48 log.txt
-rwxr-xr-x 1 cdog5000 cdog5000  801088 Feb  1 05:24 main.jar
-rw-r--r-- 1 cdog5000 cdog5000  804802 Feb  4 02:49 main2.jar
drwxr-xr-x 3 cdog5000 cdog5000    4096 Feb  3 23:11 sandbox
cdog5000@srv3:~$ sudo g++ --static -o "/home/cdog5000/cody.out" "/home/cdog5000/cody.cpp"

As you can see it works if I do it via the SSH but not the Java code?

The Java code:

 public static Exec exec(String cmd){
        Exec exec = new Exec(cmd);
        try {
            long current = System.currentTimeMillis();
            Process proc = Runtime.getRuntime().exec(cmd);
            exec.setReturnValue(proc.waitFor());
            exec.setRunTime(System.currentTimeMillis() - current);
            BufferedInputStream bos = new BufferedInputStream(proc.getInputStream());
            byte b[] = new byte[1024];
            String content = "";
            while(bos.read(b) != -1) {
                content += new String(b);
            }
            exec.setStdIn(content.split("\n"));
            content = "";
            bos = new BufferedInputStream(proc.getErrorStream());

            while(bos.read(b) != -1) {
                content += new String(b);
            }
            exec.setStdErr(content.split("\n"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return exec;
    }

Thanks for any help and it is apprectiated!

  • 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-20T02:56:29+00:00Added an answer on May 20, 2026 at 2:56 am
    Err: g++: "/home/cdog5000/cody.cpp": No such file or directory
    

    Is telling you the problem.

    You have one level of quotes too many, so you’re looking for "/home/cdog5000/cody.cpp" rather than /home/cdog5000/cody.cpp.

    The Runtime.exec documentation says:

    More precisely, the command string is broken into tokens using a StringTokenizer created by the call new StringTokenizer(command) with no further modification of the character categories. The tokens produced by the tokenizer are then placed in the new string array cmdarray, in the same order.

    Meaning it only splits on whitespace, it doesn’t handle double quotes like the shell does.

    Many languages have two functions, one called exec which runs the command verbatim, and system which passes the string to the shell, where it will split words and expand wildcards.

    I can’t see a system call in Java, so I think you will have to use exec(String[] cmdarray) rather than exec(String command).

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

Sidebar

Related Questions

I have been developing in asp.net since its existence (also classic asp before that)
I have been developing with Java for several years and last six months I
I have been tasked with developing a solution that tracks changes to a database.
I have been working on a mysql database that I set up with phpmyadmin...
People have been developing own solutions to the following problems: Consistent messaging frameworks for
I have been developing websites for a couple of years now and I almost
I have been developing a C# windows form application in XP. It all works
Up till now I have been developing my personal and school projects at home
There are several people about (myself being one of them) who have been developing
Like most developers here and in the entire world, I have been developing software

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.