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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:54:42+00:00 2026-06-11T05:54:42+00:00

I have a Java class that is using Runtime.exec() to execute a cscript process

  • 0

I have a Java class that is using Runtime.exec() to execute a cscript process with one String of several arguments that is retrieved from a database. One of these arguments includes newline characters that need to be preserved, but Runtime.exec() removes the newline characters. The problem doesn’t exist when using ProcessBuilder, but I’d rather not have to worry about parsing my list of arguments.

Is there a way to preserve the newlines when calling exec()?

In case anyone wants to see it, here’s a simplified example of the call to exec():

Process proc = Runtime.getRuntime().exec("cscript test.vbs \"line1\r\nline2\"");

My script was getting “line1 line2” as one argument with the newline replaced by a space.

  • 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-11T05:54:44+00:00Added an answer on June 11, 2026 at 5:54 am

    There is little information in your question but I’m wildly guessing that your issue is as follows.

    Note that the forms of Runtime.exec(...) with a String command argument will end up using a StringTokenizer to generate the actual command tokens, which might explain the unexpected removal of newline characters. Try using a form of Runtime.exec(...) with a String array command argument so that no parsing of the string command arguments occurs.

    Of course, doing so might require you to parse the arguments yourself but that might be the only way to ensure that the program does what you expect.

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

Sidebar

Related Questions

I'm using Java. I want to have a setter method of one class that
I am using java Runtime.exec() method to execute bat file,in bat file i have
I have a Java program that opens a file using the RandomAccessFile class. I'd
I have a quite huge Java class that has several imported packages and libraries
Assume we have a trivial Java program that consists of just one class: public
I'm currently working on Mangler's Android implementation. I have a java class that looks
I have a simple Java class that I need to serialize to be stored
I have a simple Java class that has some methods: public class Utils {
I have a Java class MyPojo that I am interested in deserializing from JSON.
In Java I have the necessity of implementing a class that extends Thread within

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.