Jump to content

get cmd line variable


 Share

Recommended Posts

In order to retrieve/collect the output from the console process, you'll need to use the Std*Read functions.  The linked help article below has an example which you can modify.   https://www.autoitscript.com/autoit3/docs/functions/StderrRead.htm

Spoiler

Update the Local $iPID = Run line. ;)

 

Edited by spudw2k
Link to comment
Share on other sites

Runwait returns the exitcode of the program you ran. It won't give you a session ID.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

You could do it this way, no guarantee it will work as I don't know what the DOS commands are doing.

$PID = Run(@ComSpec & 'for /f "tokens=3,4" %a in (''query session %username%'') do @if "%b"=="Active" set MY_SESSION_ID=%a', @SystemDir, @SW_SHOW, 8)
While ProcessExists($PID)
    Sleep(100)
WEnd
$MY_SESSION_ID = StdoutRead($pid)
MsgBox(1, "My Session ID", "Session ID is: " & $MY_SESSION_ID)

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Looks like you are setting the environment variable MY_SESSION_ID with the output from the command.  You should be "echo"ing it instead to output it to the console so the StdoutRead function picks it up.

edit: There was also an issue with spaces in run command so it wasn't executing.  This works for me:

#include <AutoItConstants.au3>
$sCMD = 'for /f "tokens=3,4" %a in (''c:\windows\system32\query.exe session %username%'') do @if "%b"=="Active" echo %a'

$PID = Run(@ComSpec & " /c " & $sCMD, @ScriptDir, @SW_HIDE, $STDERR_MERGED)
While ProcessExists($PID)
    Sleep(100)
WEnd
$MY_SESSION_ID = StdoutRead($pid)
MsgBox(1, "My Session ID", "Session ID is: " & $MY_SESSION_ID)

 

On 12/13/2016 at 7:50 AM, BrewManNH said:

...I don't know what the DOS commands are doing.

He's essentially parsing the output of the query session command to retrieve just the value instead of the entire line.

 

@Tigerweld no comment?

Edited by spudw2k
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...