473,659 Members | 2,872 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 5547
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.getPrope rty.
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.getPrope rty.
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.getPrope rty. 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 "environmen t 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
9627
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
8003
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...
1
1994
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. I'd like to check for a list of "int"s and i don't know how many int's are in this array, it could be
0
1012
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
2101
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: dataAdapter.SelectCommand = new SqlCeCommand("SELECT * FROM Supplier",
1
1814
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
3260
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: MySqlAdapter.InsertCommand = New SqlCommand("INSERT INTO billing( type, dsc ) VALUES ( @type, @dsc)", MySqlConnection) But it gives me the following error when MySqlAdapter.Update(MyDt) executes: Must declare the variable '@type' Could someone tell me what I'm...
0
989
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 visibility, etc) to the panels also during runtime. Once I create a bunch of panels (each using the same 'creation' code), how can I call them up again to send commands to them? I figure I can add them to an array and call them using:...
3
2407
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 give an example: in my application which will contain of several pages I'll use a filter/query mechanism, so if the user wants to add a new filter or modify
0
8851
Oralloy
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...
0
8746
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 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...
1
8525
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,...
0
8627
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 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...
1
6179
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 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...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2750
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
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
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 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...

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.