Nepomuk 3,112
Recognized Expert Specialist
Hi!
I'm trying to execute a few commands after each other with -
Runtime.getRuntime().exec("cmd /k" + ...); // or cmd /c
-
For example, I'd like to process this code:
(this is just an example of course)
Basically, I want to change the directory and then execute my command, instead of executing it in the current directory. However
lists the current directory.
Of course, this solution will be for Windows, but I'll also want to do it under Linux/UNIX, so a platform specific solution would be less desirable.
Greetings,
Nepomuk
3 5538 Nepomuk 3,112
Recognized Expert Specialist
OK, I've found the solution for my problem, even though it isn't a general solution.
I just use -
Runtime.getRuntime().exec(cmd, null, new File(targetFolder));
-
with cmd being a String containing the command and targetFolder being the Path, it should be executed in.
Nevertheless, I would like to know, how you can execute several commands in one "cmd /c" or "cmd /k".
Greetings,
Nepomuk
Hi!
I'm trying to execute a few commands after each other with -
Runtime.getRuntime().exec("cmd /k" + ...); // or cmd /c
-
For example, I'd like to process this code:
(this is just an example of course)
Basically, I want to change the directory and then execute my command, instead of executing it in the current directory. However
lists the current directory.
Of course, this solution will be for Windows, but I'll also want to do it under Linux/UNIX, so a platform specific solution would be less desirable.
Greetings,
Nepomuk
Command to change directory is different for different platforms so I don't think you can get an entirely platform independeant solution.
You could test for the os using System.getProperty.
Also for multiple commands, wouldn't a batch file (or bash) be more appropriate?
Nepomuk 3,112
Recognized Expert Specialist
Command to change directory is different for different platforms so I don't think you can get an entirely platform independeant solution.
You could test for the os using System.getProperty.
Also for multiple commands, wouldn't a batch file (or bash) be more appropriate?
In this case a batch file wouldn't be a good idea, as I have to modify the commands. (Or at least one of them.) And I'm already checking the Platform with System.getProperty. However, at least on Windows and Linux, the Command for changing directory is very similar (cd in both cases, but with Windows cd /D in some cases...).
I've been reading the Runtime API and I found something, that I don't understand and which might be the right direction: What is a "environment variable" in this case?
Greetings,
Nepomuk
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: vishnu mahendra |
last post by:
I want to execute a html file named hai.html in c:\mydocuments folder.
How can i open this file in Internet explorer or netscape?
thank you in advance ,
vishnu
|
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...
|
by: Torsten Mohr |
last post by:
Hi,
i'd like to write an extension module and use
PyArg_ParseTuple in that to parse the parameters.
I have several questions related to this that i did
not find in the documentation:
1....
|
by: Daniel |
last post by:
what is the best way to quickly make a mechanism to configure a windows
service at runtime? external app that remotes in, custom commands, pulling
mechanism to config file?
|
by: Ghost |
last post by:
Hello.
I have such question:
I want to create SqlCeDataAdapter object at runtime...
I'm writing:
SqlCeDataAdapter dataAdapter = new SqlCeDataAdapter();
then I specify Select Command:...
| |
by: Faraz |
last post by:
Hey guys.
How cam I interface with the environment in C#. I want to execute commands
in a (separate) process, just like java Runtime.exec(string command) does.
Thanks in advance,
|
by: cj |
last post by:
I'm having a problem writing an insert command to work with a datatable.
I've looked at what the sqldataadapter creates and created my insert
command to look the same. I have:...
|
by: rhyspatto |
last post by:
Hi, I have a problem but cannot figure out a good solution to it.
I am trying to create a form that creates a bunch of panels during runtime, and I want to be able to send commands (such as false...
|
by: ton |
last post by:
Hi,
I'm using AJAXPRO this works very well.
What I want to do is to add new page elements at my web site without using a
postback. And I do not mean listitems but a complete dialog. Let me...
|
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,...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |