command

Running Powershell script remotely through Java

天涯浪子 提交于 2019-12-02 05:46:57
问题 I am able to run the below powershell command through Powershell itself, invoke-command -ComputerName "compName" -filepath "c:\script.ps1" -credential "admin" but when I try running that through Java, I get an error. Sounds like "Invoke-command" is not recognized as a program to be run though Java. If this is the case, is there any other solution? Process p = new ProcessBuilder() .inheritIO() .command("invoke-command", "-computername", "compName", "-filepath", "C:\\script.ps1").start(); The

Java - execute a program with options, like ls -l

痞子三分冷 提交于 2019-12-02 05:44:24
In Java, how do I execute a linux program with options, like this: ls -a (the option is -a), and another: ./myscript name=john age=24 I know how to execute a command, but cannot do the option. You need to execute an external process, take a look at ProcessBuilder and just because it almost answers your question, Using ProcessBuilder to Make System Calls UPDATED with Example I ripped this straight from the list example and modified it so I could test on my PC and it runs fine private static void copy(InputStream in, OutputStream out) throws IOException { while (true) { int c = in.read(); if (c

Batch: During my code loop it stops setting a variable. All Help Welcome

旧时模样 提交于 2019-12-02 05:41:32
goto time :time set tm=%time% set hh=%tm:~0,2% set mm=%tm:~3,2% set ss=%tm:~6,2% set ms=%tm:~7,2% goto date :date set dt=%date% set wd=%dt:~0,3% set mh=%dt:~4,2% set dy=%dt:~6,2% set yr=%dt:~8,4% goto scheduletimes :scheduletimes goto hour1 :hour1 for /f "tokens=1*delims=0" %%a in ("$0%hh%") do set /a "HH"="%%b" if %HH% equ 6 goto minutes1 pause goto time :minutes1 for /f "tokens=1*delims=0" %%a in ("$0%mm%") do set /a "MM"="%%b" if "%MM%"=="00" goto seconds1 pause goto time :seconds1 for /f "tokens=1*delims=0" %%a in ("$0%ss%") do set /a "SS"="%%b" if %SS% lss 10 goto day1 pause goto time

How to split string using batch file?

馋奶兔 提交于 2019-12-02 05:06:20
How to split string using batch script? SET java_path="C:\Program Files\Java\jdk1.6.0_31" above is my string, i want only "C:\Program Files" from java_path. how to get it? You may split strings by character position: ECHO %java_path:~1,16% or by splitting at specific characters: FOR /F "DELIMS=\ TOKENS=1,2" %i IN (%java_path%) DO ECHO %i\%j try this: @ECHO OFF &SETLOCAL SET "java_path=C:\Program Files\Java\jdk1.6.0_31" SET "this=%java_path:~3%" SET "this=%this:*\=%" CALL SET "this=%%java_path:%this%=%%" SET "this=%this:~0,-1%" ECHO %this% 来源: https://stackoverflow.com/questions/17744267/how-to

How can I use command line arguments to control a batch program that prints multi-colour text?

走远了吗. 提交于 2019-12-02 04:39:52
I have a batch script that can display two or more colors of text on the same line in the command prompt. (below) @echo off SETLOCAL EnableDelayedExpansion for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do ( set "DEL=%%a" ) echo say the name of the colors, don't read call :ColorText 0a "blue" call :ColorText 0C "green" call :ColorText 0b "red" echo( call :ColorText 19 "yellow" call :ColorText 2F "black" call :ColorText 4e "white" pause goto :eof :ColorText echo off <nul set /p ".=%DEL%" > "%~2" findstr /v /a:%1 /R "^$" "%~2" nul del "%~2" > nul 2>&1

How to run a java project with vm arguments from command line?

£可爱£侵袭症+ 提交于 2019-12-02 04:10:21
I'm writing a maven plugin which has to initialize another java project with specific VM arguments. according to the exec:java, they only take in arguments but not VMarguments, so my question is how to launch a java project with specific VMarguments from the command line? thanks You can't supply extra VM arguments if you use Maven's exec:java plugin because it runs in the same VM (i.e. it's already been initialized). You'll need to use exec:exec, and construct the java command line yourself. 来源: https://stackoverflow.com/questions/7305090/how-to-run-a-java-project-with-vm-arguments-from

Running Powershell script remotely through Java

风流意气都作罢 提交于 2019-12-02 03:03:17
I am able to run the below powershell command through Powershell itself, invoke-command -ComputerName "compName" -filepath "c:\script.ps1" -credential "admin" but when I try running that through Java, I get an error. Sounds like "Invoke-command" is not recognized as a program to be run though Java. If this is the case, is there any other solution? Process p = new ProcessBuilder() .inheritIO() .command("invoke-command", "-computername", "compName", "-filepath", "C:\\script.ps1").start(); The error, Cannot run program "invoke-command": CreateProcess error=2, The system cannot find the file

execlp multiple “programs”

荒凉一梦 提交于 2019-12-02 00:48:31
I want to run something like cat file.tar | base64 | myprogram -c "| base64 -d | tar -zvt " I use execlp to run the process. When i try to run something like cat it works, but if i try to run base64 -d | tar -zvt it doesn't work. I looked at the bash commands and I found out that I can run bash and tell him to run other programs. So it's something like: execlp ("bash", "-c", "base64 -d | tar -zvt", NULL); If I run it on the terminal, it works well, but using the execlp it dont work. If I use execlp("cat", "cat", NULL) it works. Someone knows how to use the -c param on execlp to execute

How to send a string to the terminal without having it to be a standard command?

牧云@^-^@ 提交于 2019-12-02 00:03:58
I am writing a program in Java that needs to use terminal command to work. My function basically looks like this : public void sendLoginCommand() throws IOException { System.out.println("\n------------Sending Login Command------------\n"); String cmd="qskdjqhsdqsd"; Runtime rt = Runtime.getRuntime(); Process p=rt.exec(cmd); } public Process sendPassword(String password) throws IOException { System.out.println("\n------------Sending Password------------\n"); String cmd=password; Runtime rt = Runtime.getRuntime(); Process p=rt.exec(cmd); return p; } public void login(String password) throws

Tcsh run command if command was run

痞子三分冷 提交于 2019-12-01 23:51:13
I'm not really familiar with TCSH I would like run a command2 if a command1 was entered in the shell, something like this: if command1 then echo "Command succeeded" command2 else echo "Command failed" fi I tried this code but it doesn't work. Step two would be to read and print in a file a part some variable that command1 changed (making a kind of history only for some variables). You can use $? to get exit code from last command. #!/bin/tcsh # command below can fail or succeed command1 if ( $? == 0 ) then command2 else echo "command1 failed" endif 来源: https://stackoverflow.com/questions