I want to be able to run an external cmd prompt concurrently with my Java code. While running java application need to start external cmd prompt ,and this command prompt need to updated from my java application as well as i need to get values from this command prompt into java application.Please provide suitable suggestion
Try this
Runtime rt = Runtime.getRuntime();
rt.exec("cmd.exe /c start command");
UPDATION 2
To execute commands try this
rt.exec("cmd.exe /c start cmd.exe /k \"ping localhost\"");
Related
In Jenkins: I'm having a windows batch command which runs:
wmic /node:[server name] process call create "cmd.exe /c [bat file]".
The problem is that the coming step in the jenkins project (also windows batch command) runs before the batch tasks (restore DB etc.) complete.
I would like to know how can make the first windows batch command wait until completed, so that the second step won't run yet.
So i'm trying to write a script which checks if the cmd is with administrative privileges. If it is I just ran the command - which is a jar file. If it isn't what I did was create a link to the cmd and in that link I made it always run as administrator.
The problem is that after it runs the command it opens the second cmd as administrator but then the command needs to be written again. Is there any chance to save the command written and as the second cmd opens run it?
net session >nul
if %errorLevel% == 0 (
java -jar %~dp0/myjar.jar%*
) else (
echo Administrative permissions required
cmdadmin.lnk
)
cmdadmin.lnk is as I said a link to cmd which in the advanced properties I set as run as administrator.
Now what I want is to pass a command when opening the link. Is it possible?
I work on my computer A.
I would like to run a batch script.bat on my computer B (C:\Documents\script.bat). The password of the admin session of B is PASSWORD.
This is my command to execute my batch from computer B :
start C:\Documents\script.bat
Now, I would like to run it with this argument : 3.2.16
I've tried these 3 commands but it says "incorrect caracter"
start C:\Documents\script.bat "3.2.16"
start C:\Documents\script.bat '3.2.16'
start C:\Documents\script.bat 3.2.16
Also, I would like to run it from my computer A.
Can you help me please ? Thank you in advance.
If you want to run a process remotely, you'll either need to use Sysinternals psexec, or wmic. The difference is that psexec diverts its output to the computer it's invoked from; whereas wmic displays a window on the remote PC.
If you're curious, the wmic command syntax is as follows:
wmic /node:remotePC /user:remotePC\user /password:password process call create 'cmd /c "c:\path\to\script.bat" "arg1" "arg2"'
If you need to view the output of script.bat, redirect the output remotely to a text file, then read the text file.
wmic /node:remotePC /user:remotePC\user /password:password process call create 'cmd /c blah ^>c:\output.txt'
net use z: \\remotePC\c$ /user:remotePC\user password
type z:\output.txt
del z:\output.txt
net use z: /delete
...for example. But it's probably easier just to download and use psexec.
As the title suggests, I have an added parameter in my Task Scheduler Actions that logs stdout and stderr to a log.txt file. The logging works when the action is run through the command prompt, but not when the action is run by the actual Task Scheduler (at its specified time). Task scheduler reports the action runs successfully, but I can't be sure it does because there's no logging:)
Command looks like this
powershell.exe -file "D:\Scripts\TimeSync2.ps1" > "D:\Scripts\timeSync_log.txt" 2>&1
I'm unfortunately not a native Windows user, so any help would be appreciated. I'm running Windows Server 2008 R2 Enterprise.
Thanks!
Cmd.exe handles command redirection. You have to run it under cmd.exe. Powershell probably also can do redirection but in your script (.NET can).
A black window just means a console program is running. Only if cmd is running does cmd features become available. By starting cmd or by putting it in a batch you canget redirection from cmd.
cmd /c powershell.exe -file "D:\Scripts\TimeSync2.ps1" > "D:\Scripts\timeSync_log.txt" 2>&1
See for Help
cmd /?
Place the command you listed in a batch file and then schedule the batch file.
If you are doing so and it fails, then try it with your account credentials as authentication in task scheduler, to see if it is a permissions issue.
#echo off
powershell.exe -file "D:\Scripts\TimeSync2.ps1" > "D:\Scripts\timeSync_log.txt" 2>&1
I'm using chef for windows and need to run a batch file that starts up the selenium-server java service (java -jar seleniumserver.jar) as a daemon. When I try to use a windows_batch resource, it causes chef to hang during it's provisioning.
The problem is that the selenium server stays running in whatever command line you start it in, but chef won't continue provisioning the machine until the command is finished. The thing is, the command never finishes, it's not supposed to.
Here's what I've tried so far:
Executing java -jar seleniumserver.jar & (with the windows_batch resource)
Using a template to create a batch file for the command, then using windows_batch to execute file.bat
Using windows_batch to execute the batchfile with an & (file.bat &)
I'm open to any ideas, even if it's kind of hacky. Thanks in advance!
If I understand the question correctly, you can start a separate process so the main batch file ends. For example:
start java -jar seleniumserver.jar
You can control several execution parameters through the different start options.
Ending command lines with & does not do the same as *nix.
async process on windows that doesn't block chef run
batch "run" do
code 'powershell -c "start-process notepad.exe"'
end
The following is an example of using start-process to start a command with arguments.
Try running the command by itself in the command prompt to familiarize yourself with its output.
net statistics server
Now run it using powershell and start-process in the command prompt and verify the correct output shows in c:\output.txt. Please pay careful attention to the use of single or double quotes. My experience says start-process won't work with double quotes for some reason.
powershell -c start-process net -ArgumentList 'statistics workstation' -RedirectStandardOutput c:\output.txt
Now put the following in a Chef execute resource and run it. Again, be aware of the single quotes, double quotes and escaped single quotes.
execute "run" do
command 'powershell -c "start-process net -ArgumentList \'statistics workstation\' -RedirectStandardOutput c:\chef-output.txt"'
end
You should find the correct output in c:\chef-output.txt.