B4J Question Shutting down PC with Jshell

Reminisce

Active Member
Hello everyone, I've searched the forum, but nothing comes close to what I want to achieve. I built a simple app on b4a, that uses socket and asynstreams to send commands to my b4j client. But jshell is not executing those commands.

B4X:
Sub astreams_NewData (Buffer() As Byte)
	Dim receivecommand As String = BytesToString(Buffer,0,Buffer.Length,"UTF-8")
	
	Select receivecommand
		
		Case "SHUTDOWN"
			Dim l As List
			Log(receivecommand)
			l.Initialize
			l.Add("SYSTEMINFO")
			shell.Initialize("shell","cmd.exe",l)
			shell.WorkingDirectory = "C:\WINDOWS\system32\"
			shell.Run(-1)
			Wait For  shell_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
			Log(StdOut)
			Log(Success)
					
	End Select
	
End Sub

[\code ]

The above code receives the command, but doesn't execute it. I
 

Reminisce

Active Member
I don't undrratsd
Tip:
B4X:
Dim l As List
            Log(receivecommand)
             l.Add("SYSTEMINFO")
Can be written like this:
B4X:
Dim l As List = Array("SYSTEMINFO")

You probably need to add /c as the first argument.
I don't understand @Erel, where should I add /c? I expected cmd to come up with the system info command already executed. I'll need this to shutdown my pc too using the "shutdown /p" command.
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
  1. Type "shutdown /s" to Shutdown your computer;
  2. Type "shutdown /r "to Restart your windows PC;
if you want restart PC after 10 Min use: "shutdown –s –t 600"
 
Upvote 0

Reminisce

Active Member
  1. Type "shutdown /s" to Shutdown your computer;
  2. Type "shutdown /r "to Restart your windows PC;
if you want restart PC after 10 Min use: "shutdown –s –t 600"
Thanks for your reply. I know these commands. My problem is jshell isn't executing them whenever I pass it.
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Look also this:
 
Upvote 0

Reminisce

Active Member
Look also this:
Thank you, I'll try the power shell example in the other thread. On another hand, what if I save these commands in a ".bat" file. How do I execute bat files.?
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User

and



But anyway Olivers example works without problem
 
Upvote 0
Top