Nepomuk 3,112
Recognized Expert Specialist
Hi!
I'm trying to run an external Program with -
Process p = Runtime.getRuntime().exec("/bin/sh -c \"/bin/gzip -c /home/user/workspace/TarGz/pics.tar > pics.tar.gz\"");
-
CleanStream cleanError = new CleanStream(p.getErrorStream(), "ERROR");
-
CleanStream cleanOutput = new CleanStream(p.getInputStream(), "OUTPUT");
-
clearError.start();
-
clearOutput.start();
-
p.waitFor();
-
under Linux.
Here's the CleanStream.jav a: -
import java.io.BufferedReader;
-
import java.io.IOException;
-
import java.io.InputStream;
-
import java.io.InputStreamReader;
-
-
public class ClearStream extends Thread {
-
InputStream is;
-
String type = null;
-
boolean typeSet = false;
-
-
ClearStream(InputStream is)//, String type)
-
{
-
this.is = is;
-
//this.type = type;
-
}
-
ClearStream(InputStream is, String type)
-
{
-
this.is = is;
-
this.type = type;
-
typeSet = true;
-
}
-
-
public void run()
-
{
-
try
-
{
-
InputStreamReader isr = new InputStreamReader(is);
-
BufferedReader br = new BufferedReader(isr);
-
String line=null;
-
while ( (line = br.readLine()) != null)
-
{
-
System.out.print("");
-
if(typeSet) System.out.println(type + "> " + line);
-
}
-
}
-
catch (IOException ioe)
-
{
-
ioe.printStackTrace();
-
}
-
}
-
}
-
The command works fine, when used within bash, but from Java I get the error: -
ERROR> -c: 1: Syntax error: Unterminated quoted string
-
I checked the Runtime API and found, that exec(String command) has the token parsed with a StringTokenizer , which would explain, that the last quotation mark isn't found.
I tried packing the String into an array, to avoid this, by using exec(String[] cmdarray).
It looks like this then: -
String[] use = {"/bin/sh -c \"/bin/gzip -c /home/user/workspace/TarGz/pics.tar > pics.tar.gz\""};
-
Process p = Runtime.getRuntime().exec(use);
-
// same as after here
-
The error here is even worse: -
java.io.IOException: Cannot run program "/bin/sh -c "/bin/gzip -c /home/user/workspace/TarGz/pics.tar > pics.tar.gz"": errir=2, No such file or directory
-
at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
-
at java.lang.Runtime.exec(Runtime.java:593)
-
at java.lang.Runtime.exec(Runtime.java:466)
-
at TarSomething.main(TarSomething.java:18)
-
Caused by: java.io.IOException: java.io.IOException: error=2, No such file or directory
-
at java.lang.UNIXProcess.<init>(UNIXProcess.java:148)
-
at java.lang.ProcessImpl.start(ProcessImpl.java:65)
-
at java.lang.ProcessBuilder.start(ProcessBuilder.java:452)
-
... 3 more
-
(Line 18 in TarSomething is Process p = Runtime.getRunt ime().exec(use) ;)
I've been trying to solve this problem for a while, but without success.
Can anyone help me?
Greetings,
Nepomuk
1 7573 Nepomuk 3,112
Recognized Expert Specialist
OK, Problem solved.
I used this: -
String[] use = {"/bin/sh", "-c", "/bin/gzip -c /home/user/workspace/TarGz/pics.tar > pics.tar.gz"};
-
// Same from this point
-
Greetings,
Nepomuk
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Kathy Benson |
last post by:
Hi,
I need to open an external file, such as *.htm from a Java program. I
need to open this file by the default program that handles this
extension on the machine. So *.htm should always be opened by Netscape
if that is the default browser on the machine.
I figured out how to do this on NT but could not find an equivalent
command on Linux.
Here is what I did on NT.
|
by: Hal Vaughan |
last post by:
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...
|
by: |
last post by:
Maybe I ask something OS depended but maybe not. So I ask:
I want to run an external program from my C++ program.
I want stdin of external program constructed from a C++ string in my
program.
I want stdout of external program constructs a C++ string in my program.
Is this possible without intermediate temporary files?
|
by: Peter Chant |
last post by:
I hope no one minds me running this past them.
I'm running a linux machine with with apache, php and mysql. This is not
accessable from the internet. I want a server that is visable to the
internet. For that purpose I am running a user mode linux machine and using
apache on that as the external looking web server. This means that stuff I
want to see on the outside is on a copy of apache that is doing little and
does not get messed...
|
by: I. Myself |
last post by:
Suppose we spawn a child process with Popen. I'm thinking of an
executable file, like a compiled C program.
Suppose it is supposed to run for one minute, but it just keeps going
and going. Does Python have any way to kill it?
This is not hypothetical; I'm doing it now, and it's working pretty
well, but I would like to be able to handle this run-on condition. I'm
using Windows 2000, but I want my program to be portable to linux.
...
| |
by: Dylan Parry |
last post by:
Hi folks,
I'm writing a program that needs to execute an external program and wait
for it to finish running before it can make use of the output from that
program. Specifically, the external program converts from one file
format to another, and is something that I can't do natively :(
So what I need to figure out is how to:
a) Start the external program, with parameters
|
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: jfigueiras |
last post by:
>I have a problem with the module subprocess!
As many other programs...
I'm not sure what you mean by "non-standard file descriptors". The
other program is free to open, read, write, etc any file he wants -
are you trying to trap any file operation it may want to do?
You *could* do such things -google for "code injection" and "API
hooking"- but I doubt it's what you really want.
|
by: Jimmy |
last post by:
Well, i know it may be a little non-python thing, however, I can think
of no place better to post this question :)
can anyone tell me, in python, how to obtain some information of a
running program?
paticularly, if i am playing some music in audacious or other media
player, how can i get the the name and some other info of current
playing song? It seems that audicious doesn't output on run-time
|
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |