• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

ProcessBuilder incorrectly processes embedded spaces within embedded quotes as required by Windows 7

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using Windows XP+ (7, 8, etc) the file paths can have embedded spaces.

This must be processed correctly because the various product installers including Windows its self builds just such paths.

Therefore using paths without embedded spaces is NOT possible, to belay comments about just change path names.

Further, some tools require that their command line arguments use these paths.

A common type of command line argument (single quotes are my addition) might be '-I"C:\Program Files (x86)\Product\Library"'

The "s in the command line argument are required for the Windows command processor to correctly parse the command which is standard with Windows.

All solutions I found recommended on the web for processing the spaces in the path name fail with the above argument because of the use of both embedded spaces and "s.

I have found various references on the web identifying this specific problem of Java, ProcessBuilder, and Windows.

I have build simple test programs to test various options and as of yet have not found any solution.

I have escaped the "s, escaped the \s, and various combinations.

None work nor does any solution I have found on the web.

What is particularly annoying about this, is that I can pass correctly a space embedded file name/directory name but not pass a command line argument of the for -I"C:\Pro ..... mentioned above.

Example of file name path that works successfully (double \\ required by Java):

"C:\\Software Development\\MyTesting\\VS2008\\CPP\\EchoCommandLineArguments\\Debug\\EchoCommandLineArguments.exe"

Which ProcessBuilder builds process request as

C:\Software Development\MyTesting\VS2008\CPP\EchoCommandLineArguments\Debug\EchoCommandLineArguments.exe"

For the curious, EchoCommandLineArguments.exe is a quick and dirty C++ executable the echos its command line arguments.

If I go to a windows command prompt, I can type the command and arguments as required, specifically, -I"C:\Program Files (x86)\Product\Library"

Is there a solution? Or is Java not a full production environment?

I am using the following Windows 7 version 6.1, Netbeans IDE 7.4 (Build 201310111528), Java 1.7.0_45; Java HotSpot(TM) 64-Bit Server VM 24.45-b08, and Runtime Java(TM) SE Runtime Environment 1.7.0_45-b18.

I have additionally been unsuccessful using the Process.exec method.

Thanks in advance,

Pat

 
Marshal
Posts: 80222
424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please don't push enter after every sentence; it makes the text more difficult to read.
I shall move this discussion as too difficult for “beginning”.

Where are the quote marks? You have one set of arguments with quotes at both ends and one set with quotes at the tail end only. Why? Are those quotes part of the Java code or part of the String literal? Why have you not get \" at each end of the arguments?
 
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Patrick Ireland wrote:

A common type of command line argument (single quotes are my addition) might be '-I"C:\Program Files (x86)\Product\Library"'



The quoiting is required on the Windows command line because cmd.exe requires it in order to know where to split the line into arguments but using ProcessBuilder this is handled by using


i.e. since cmd.exe is not involved the cmd.exe quoting requirement is bypassed.
 
Patrick Ireland
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Richard,

You are absolute correct.
Given your suggestion, I was able to us my little test program and the arguments were indeed interpreted correctly.
The difficulty I encountered was try to exactly duplicate the string as would be typed on the command line.
I was unaware that a simple outer set of "s would be acceptable as that is not acceptable on the command line.
I must forever single your praise.
So much for 15 years of Java experience and my Java certification.
But I do have a unrelated question.
Is process generation a beginner topic as I have never seen any of process generation, threading, or synchronization covered in a beginning course for Java.
I believe ProcessBuilder was introduced in Java 7.
Have "O'Reilly"'s "Learning Java 2nd Edition", "Deitel & Deitel"'s "Java, How To Program 4th Edition", and "Java Head First (cannot currently find my copy)" been up dated to include such topics?
Typically these topics are the domain the "internals" type of developer how are hidden in back rooms never to see a customer or mere mortal programmers.
I refer humorously to the 2 systems programmers, portrayed by Maury Chaykin and Eddie Deezen, in the movie "WarGames" starring Matthew Broderick and Ally Sheedy.
Enough reminiscing, thank you again Richard.

Your lowly praiser,
Pat
 
Patrick Ireland
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Richard,

Sorry for the typos, "able to use", "sing your praise".

bowing prostrate at your feet,

Pat
 
Richard Tookey
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Patrick Ireland wrote:rtification.
But I do have a unrelated question.
Is process generation a beginner topic as I have never seen any of process generation,


Most definitely not a beginner topic as there are just too many traps. ProcessBuilder was introduced in Java 1.5 and for that release Runtime.exec() was re-written so that behind the scenes it used ProcessBuilder. The ProcessBuilder API is superior to the Runtime.exec() API and it is now the preferred method of invoking external processes.

Process object create using ProcessBuilder.start() are the same as those produced by Runtime.exec() and as such have the same problems. The ancient article http://www.javaworld.com/article/2071275/core-java/when-runtime-exec---won-t.html presents most of the problems and solutions and should be considered as the bible. Indeed your problem is hinted at in that article. If you have not read that article you should do so and to make your code bullet proof you should implement all the recommendations. Many people think they are immune to the traps and ignore some of the recommendations; they may for a time get away with it but at some point one or more of the traps will jump up and bite them.

As to your questions about the books; since Runtime.exec() was available from Java 1.1 (my first use of it Runtime.exec()) and maybe even 1.0 (I never used 1.0 in anger) and Runtime.exec() was not considered a topic to include in Java books I can't see why ProcessBuilder, which is essentially just a re-write of Runtime.exec(), should be. I have never read any of those books and am unlikely to do so.
 
Patrick Ireland
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Richard,

I will certainly read the article.
As to the books I have, I have an extensive library.
I have taught many programming languages, such as COBOL, FORTRAN, PASCAL, C, C++, Assembler, HTML, PERL, Java, C#, and VB (6 and .net).
I have over 30 books alone on Java and various encompassing topics, such as Struts, Swing, and J2EE.
I have been done systems programmer, DBA, real-time, hardware design, GUI, and design patterns to mention a few.
Basically, any technical and/or bleeding edge technology.
Doing all of this, I have accumulated a few books.
The books I mentioned in my prior post were all introductory books so I am curious, how did you initially learn Java?
Did you have a reference book? If so, which book was it.
Your learning path may be superior to the traditional paths from those introductory books.
My introduction to Java was a very poorly written Sun manual.
The my Java introductory books were accumulated as I taught Java.
It seems that you and I have chewed up some of the same non-traditional ground in the multi-processing environment.

Thank you again,

Pat
 
Campbell Ritchie
Marshal
Posts: 80222
424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would think Runtime#exec and ProcessBuilder are topics too advanced to appear in any of the books you mentioned. I couldn't even find it in my 2005 edition Horstmann and Cornell (I don't have a more recent edition to hand just at the moment).

And well done sorting it out
 
Power corrupts. Absolute power xxxxxxxxxxxxxxxx is kinda neat.
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic