I need to be able to run external commands from within a Java program, on
Linux and Windows (and eventually OSX). Under most circumstances there is
no problem, but if the path I specify as part of the command has any spaces
in it, or an argument for the command is a path with a space in it, or if I
redirect the output to a file with a space in the filename, it doesn't work
on Linux. I tried putting the paths in both single and double quotations,
and also tried using a backslash to escape the space within the path.
Nothing seems to work and it seems almost impossible to run an external
command from Java if there is a space in the filename. (I'm using 1.4.2.)
Any help on this would be appreciated.
Hal 3 8000
"Hal Vaughan" <ha*@thresholdd igital.com> wrote in message
news:y6R6c.4656 9$SR1.79605@att bi_s04... I need to be able to run external commands from within a Java program, on Linux and Windows (and eventually OSX). Under most circumstances there is no problem, but if the path I specify as part of the command has any
spaces in it, or an argument for the command is a path with a space in it, or if
I redirect the output to a file with a space in the filename, it doesn't
work on Linux. I tried putting the paths in both single and double quotations, and also tried using a backslash to escape the space within the path.
Nothing seems to work and it seems almost impossible to run an external command from Java if there is a space in the filename. (I'm using 1.4.2.)
Any help on this would be appreciated.
Hal
In Windows, try the DOS long filename shortcut. "Program Files" becomes
"Progra~1". Spaces are eliminated, I believe, so "A Directory" would be
"ADirec~1". It numbers sequentially, so "A Directory" and "A Directory with
Pictures" would come out "ADirec~1" and "ADirec~2", respectively.
Hal Vaughan wrote: I need to be able to run external commands from within a Java program, on Linux and Windows (and eventually OSX). Under most circumstances there is no problem, but if the path I specify as part of the command has any spaces in it, or an argument for the command is a path with a space in it, or if I redirect the output to a file with a space in the filename, it doesn't work on Linux. I tried putting the paths in both single and double quotations, and also tried using a backslash to escape the space within the path.
Nothing seems to work and it seems almost impossible to run an external command from Java if there is a space in the filename. (I'm using 1.4.2.)
Any help on this would be appreciated.
Hal
Hal,
Without knowing exactly how you are executing the commands, it will be
difficult to help you. In general, I would suggest that you use the
version of Runtime.exec() that accepts a an array of Strings instead of
the one accepting a single String. Each element in the array becomes a
command parameter to the executed process so there is no need for
quoting, et cetera.
Second, how are you "redirectin g output"? Java only supports this by
using the streams that result from the Process object returned by
Runtime.exec(). If you were using that technique, you would have
probably said that you cannot open a file spaces in the name. So it
seems that you are likely using a shell to redirect output. This will
complicate matters. You must be aware that it is the shell (MS-DOS,
bash, csh, etc.) that handles stream redirection using the > and <
characters.
Ray
Raymond DeCampo wrote: Hal Vaughan wrote: I need to be able to run external commands from within a Java program, on Linux and Windows (and eventually OSX). Under most circumstances there is no problem, but if the path I specify as part of the command has any spaces in it, or an argument for the command is a path with a space in it, or if I redirect the output to a file with a space in the filename, it doesn't work on Linux. I tried putting the paths in both single and double quotations, and also tried using a backslash to escape the space within the path.
Nothing seems to work and it seems almost impossible to run an external command from Java if there is a space in the filename. (I'm using 1.4.2.)
Any help on this would be appreciated.
Hal Hal,
Without knowing exactly how you are executing the commands, it will be difficult to help you. In general, I would suggest that you use the version of Runtime.exec() that accepts a an array of Strings instead of the one accepting a single String. Each element in the array becomes a command parameter to the executed process so there is no need for quoting, et cetera.
I didn't even realize that another one existed. (One problem with being
self taught is that I always have to dig out what I need and often don't
see something "close by" or related that might help.) Using an array for
arguments might help me in some cases. Thanks!
Second, how are you "redirectin g output"? Java only supports this by using the streams that result from the Process object returned by Runtime.exec(). If you were using that technique, you would have probably said that you cannot open a file spaces in the name. So it seems that you are likely using a shell to redirect output. This will complicate matters. You must be aware that it is the shell (MS-DOS, bash, csh, etc.) that handles stream redirection using the > and < characters.
That explains it! So Runtime doesn't call the shell? That would make sense
and explain some of the problems I've had.
Thanks! Your post explains a lot and points me in a a few new directions.
Hal
Ray This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Will Seay |
last post by:
At the end of this message I've pasted a script we're trying to modify
slightly. I don't believe it is VBscript or javascript but these are
the closest groups I could find with my limited programming knowledge.
Basically, we are trying to add a few lines to this script that will
execute a few shell commands (see comments at the very end of the
code). We think this may be ActionScript2 but aren't sure.
If you can offer any help, or know...
|
by: jsw_nz |
last post by:
Helo, my first post here....
I am trying to run an agent application that converts and imports two
tables from MS Access into mySql.
(Intelligent Converters - Access2mySql)
I have run similar scripts to do mysql dumps using the system function.
Not sure if the paths included in the parameters are correct:
<?php
function import_data() {
|
by: Michael Bulatovich |
last post by:
I have a simple db to keep track of work/time/projects etc. It has two
fields (column) named "start time" and "end time"
WITH THE SPACES. I'm trying to do some automation to a form associated with
the db and notice that in all the examples
I've seen nobody EVER includes spaces in the names of fields. Now I'm
getting a sinking feeling....
Can anyone quickly outline the kinds of problems I'm going to encounter with
these names?
--
|
by: Franck Diastein |
last post by:
Hi,
I'm designing an application, and I would like to be able to receive
external commands... I would like a behavior like eMule, when you click
on an ed2k link, the link is added to eMule, even if this app is running...
How can I handle this behavior in my app ?
TIA
|
by: Tommy B |
last post by:
I'm currently working on a script that I will run when I leave my
computer on at night. It runs external commands like Ad-Aware, Spybot,
AVG, Avast, and the like. The problem is, I want to know how to make it
so that one command starts only after the last one finishes. When I run
them, they end up running all at once! Can someone please tell me if
this is possible? Judging from what I've seen in Python's versitility,
I bet it can...
| |
by: holysmokes99 |
last post by:
I have a VB6 application that references a few .Net 1.1 components, and
one 2.0 component. Does that mean that all will be running under 2.0?
Is there any way to force the 1.1 pieces to run under 1.1, and the 2.0
to run under 2.0? I know about setting a config file to force a certain
framework, but I think that is only good for the entire application.
Thanks
|
by: JJM0926 |
last post by:
I'm trying to create a running totals query in access 97. I have
followed the directions on how to do it from Microsofts website
article id 138911. I took their code they had and replaced it with my
fields. When I try to run it I get #errors in my RunTot column. I'm
kinda new to this. Not sure if maybe I mistyped something wrong or is
there a better way to do this? I have pasted the code. Any help would
be greatly appreciated....
|
by: =?Utf-8?B?Q2lhcmFuIE8nJ0Rvbm5lbGw=?= |
last post by:
On reflection, you could possibly make the app a self extracting zip file
which extracts the EXE and a settings file and then starts the app, then when
you app closes, it can repack the settings file and itself into the exe. You
would probably want a tool for this bit which could be in the zip too.
So the app isnt single exe when running but when not running, it is.
Just an idea for you to think about.
Another option would possibly be to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |