Remote Netstat to STDOUT with WMIC? - wmic

I would like to use WMIC to retrieve the output of a "netstat" command on a remote computer. The actual execution of the following command executes without error and I see the output popup briefly within a new window:
wmic /node:server1 process call create "netstat.exe -ano"
With that being said, I need to pipe the output of the process window to STDOUT, and have tried:
wmic /node:server1 process call create "netstat.exe -ano > C:\temp\test.txt"
However, that does not work. I have also tried the /output:STDOUT option, however, that only reports the execution of the command:
Executing (Win32_Process)->Create() Method execution successful. Out Parameters: instance of __PARAMETERS {
ProcessId = 5044;
ReturnValue = 0; };
Does anyone know how I can go about using WMIC to retrieve the actual output from the new window that was opened in order to process the data?
Thanks in advance!

The > symbol behaves as operator of redirection in cmd.exe, not in netstat.exe.
In fact, wmic process call create "netstat.exe -ano > C:\temp\test.txt" is about to run the same as netstat.exe -ano ^> files\nstat.txt (try it from command line).
Next command works (unfortunately, I can't try it with /node:"server1" against a remote computer at the moment):
wmic process call create "cmd /C > C:\temp\test.txt 2>&1 netstat.exe -ano"

Related

how to Add multiple cmd shell command lines vb.net

I want to run a few command lines by shell after I run the first command
I use the following command but it does not work
Shell("cmd.exe /k" + "<adb shell 1> & <su 2> & <mv /data/local/tmp/build2.prop /system/build.prop 3>")
For example, I execute the following commands in cmd
adb shell
su
mv /data/local/tmp/build2.prop /system/build.prop
How can I run vb.net?
edite -----------------------------------------------------
Honestly, we need to transfer the file to vb.net into the Android device /system folder
We use androidlib by the following command, but it does not work
Adb.ExecuteAdbCommand(Adb.FormAdbCommand("shell", "su", "-c", "mount -o remount, rw /system"))
Adb.ExecuteAdbCommand(Adb.FormAdbCommand("shell", "su", "-c", "cat /data/local/tmp/build2.prop > /system/build.prop"))
This command executes the read-only file system error
What you appear to be after is executing additional commands inside adb, in which case what you're currently doing will not work. Combining commands with the ampersand & will execute each command separately, not in a previously opened process.
To do what you want you've got to redirect standard input for the adb process, not CMD.
Redirecting the input is simply a way of changing where the process gets its input from. Instead of getting it from the keyboard input stream (the user) you can redirect it to a different stream which you have control over.
Untested, but something like this should work:
Dim psi As New ProcessStartInfo("adb", "shell 1")
psi.UseShellExecute = False
psi.RedirectStandardInput = True
Dim p As Process = Process.Start(psi)
Dim InputStream As StreamWriter = psi.StandardInput
InputStream.WriteLine("su 2")
InputStream.WriteLine("mv /data/local/tmp/build2.prop /system/build.prop 3")

Execute any bash command, get the results of stdout/stderr immediatly and use stdin

I would like to execute any bash command. I found Command::new but I'm unable to execute "complex" commands such as ls ; sleep 1; ls. Moreover, even if I put this in a bash script, and execute it, I will only have the result at the end of the script (as it is explain in the process doc). I would like to get the result as soon as the command prints it (and to be able to read input as well) the same way we can do it in bash.
Command::new is indeed the way to go, but it is meant to execute a program. ls ; sleep 1; ls is not a program, it's instructions for some shell. If you want to execute something like that, you would need to ask a shell to interpret that for you:
Command::new("/usr/bin/sh").args(&["-c", "ls ; sleep 1; ls"])
// your complex command is just an argument for the shell
To get the output, there are two ways:
the output method is blocking and returns the outputs and the exit status of the command.
the spawn method is non-blocking, and returns a handle containing the child's process stdin, stdout and stderr so you can communicate with the child, and a wait method to wait for it to cleanly exit. Note that by default the child inherits its parent file descriptor and you might want to set up pipes instead:
You should use something like:
let child = Command::new("/usr/bin/sh")
.args(&["-c", "ls sleep 1 ls"])
.stderr(std::process::Stdio::null()) // don't care about stderr
.stdout(std::process::Stdio::piped()) // set up stdout so we can read it
.stdin(std::process::Stdio::piped()) // set up stdin so we can write on it
.spawn().expect("Could not run the command"); // finally run the command
write_something_on(child.stdin);
read(child.stdout);

Declare bash variables inside sql EOF

how to declare variable in bash command. See "?"
I thought we could almost run any bash statement with ! or host in front of line
#!/bin/bash
sqlplus scott/tiger#orcl << EOF
! export v10="Hi" Doesn't work, why?
! echo $v10 Doesn't work, why?
! echo "Done" Works perfectly and also other bash commands
select * from dept; Works perfectly
exit
EOF
Thank you
What #jordanm says "probably" is exactly what is happening. When you specify a host command from within sqlplus, a separate shell process is spawned, the command executed by that process, then that process is terminated and control returns to sqlplus. Any environment variables that are set in that child shell process are good only within it, so when it terminates, they are gone.
As for your specific lines that "work" and "don't work" .. "export v10="Hi" does work but there is no stdout display of the 'export' command, and as explained, that variable v10 ceases to exist once the child process completes and control returns to sqlplus. The "echo $v10" also works, but since that is a new shell process, it has no value for $v10, so there is nothing to echo.
What are you trying to accomplish by setting enviornment variables from within sqlplus?
found it, all I had to do was
<< EOF
whenever sqlerror exit failure rollback
whenever oserror exit failure rollback
#scriptname.sql
EXIT
EOF

Runing pentaho command from a scheduler (tidal)

I am trying to execute the pentaho job over the windows through TIDAL, but the TIDAL does not execute the job at all. But when i run seperately on CMD PROMPT is executes.
The below is command used, IT does not the read the parameters assigned to it.
Kindly suggest on what has to be done.
E:\apps\Pentaho\data-integration\kitchen.bat /rep:Merlin_Repository /user:admin /pass:admin /dir=wwclaims /job=J-CLAIMS /level:Basic
You forgot a slash in /dir: option and you must use : not = symbols in your command.
For example in a windows batch script command
#echo off
SET LOG_PATHFILE=C:\logs\KITCHEN_name_of_job_%DATETIME%.log
call Kitchen.bat /rep:"name_repository" /job:"name_of_job" /dir:/foo/sub_foo1 /user:dark /pass:vador /level:Detailed >> %LOG_PATHFILE%`

How to write a ping to a text file using VBS

If I am using VBS to run some CMD commands, in this example ping, how could I write the command to a text file using VBS not DOS?
Set objCmdTest = WScript.CreateObject ("WScript.Shell")
Set Output = CreateObject("Scripting.FileSystemObject").OpenTextFile("C:\vbs\test.txt",8,true)
Output.WriteLine (objCmdTest.run ("ping failboat"))
Output.WriteLine (objCmdTest.run ("ping 8.8.8.8"))
So this is what I'm working with however what happens is; The script runs, the file is made, 2 command prompts open to run the pings and finally the text inside the file reads:
0
0
When I'd much prefer it to have the ping output.
FYI: Please don't offer suggestions that require me to use DOS for the writing, I'd like to see how VBS can do what I need for multiple reasons, thanks!
The instruction Output.WriteLine (objCmdTest.run ("ping failboat")) will write the return value of the Run method to the output file. If you want to append the command output to an output file you have to either redirect the output in the command:
objCmdTest.run "%COMSPEC% /c ping failboat >>C:\vbs\test.txt", 0, True
or use Exec instead of Run:
Set ping = objCmdTest.Exec("ping failboat")
Do While ping.Status = 0
WScript.Sleep 100
Loop
Output.WriteLine ping.StdOut.ReadAll
WScript.Shell's run method returns the process's exit code. In order to get access to an application's output, you need to use the exec method instead, and use the object that returns to get access to the process's standard output through its StdOut property.