473,503 Members | 11,508 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Several commands in one Runtime

Nepomuk
3,112 Recognized Expert Specialist
Hi!
I'm trying to execute a few commands after each other with
Expand|Select|Wrap|Line Numbers
  1. Runtime.getRuntime().exec("cmd /k" + ...); // or cmd /c
  2.  
For example, I'd like to process this code:
Expand|Select|Wrap|Line Numbers
  1. cd /D D:\
  2. dir
  3. exit
  4.  
(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
Expand|Select|Wrap|Line Numbers
  1. cd /D D:\ && dir
  2.  
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
Sep 24 '07 #1
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
Expand|Select|Wrap|Line Numbers
  1. Runtime.getRuntime().exec(cmd, null, new File(targetFolder));
  2.  
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
Sep 24 '07 #2
r035198x
13,262 MVP
Hi!
I'm trying to execute a few commands after each other with
Expand|Select|Wrap|Line Numbers
  1. Runtime.getRuntime().exec("cmd /k" + ...); // or cmd /c
  2.  
For example, I'd like to process this code:
Expand|Select|Wrap|Line Numbers
  1. cd /D D:\
  2. dir
  3. exit
  4.  
(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
Expand|Select|Wrap|Line Numbers
  1. cd /D D:\ && dir
  2.  
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?
Sep 24 '07 #3
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
Sep 24 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
9615
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
3
7992
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...
1
1988
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....
0
1002
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?
0
2090
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:...
1
1800
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,
10
3246
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:...
0
984
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...
3
2404
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...
0
7212
marktang
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,...
0
7364
jinu1996
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...
0
7470
tracyyun
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...
0
5604
agi2029
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,...
1
5026
isladogs
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...
0
4696
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...
0
3186
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...
1
751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
405
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.