Sign in to follow this  
Followers 0
reizarf27

DOS command output problem

7 posts in this topic

I want to generate a list of available printers on a print server, then import this list into a combo box in an AutoIt GUI. The print server has a command that I can run from a command prompt at a windows workstation to generate the list. The command is:

iprntcmd.exe -L iprint

If I run the command and redirect the output to a file:

"iprntcmd.exe -L iprint > c:\test.txt"

I get a test.txt file that reads as a single line of text in wordpad. I want to create a GUI combo list with each printer being on it's own line. The formatting of the output file is causing me a great deal of problems when trying to create a GUI combo list entry for each printer. I can get a list, but there is an empty line in between each printer in the combo box. I am using this code:

RunWait(@ComSpec & " /c " & 'iprntcmd.exe -L iprint > "C:\Program Files\WCF\Printman\netprinter.txt"', @WindowsDir, @SW_HIDE)
GuiCreate("iPrint Manager", 400, 500)

$printlist = GUICtrlCreateCombo("Available Printers", 20, 40, 160, 100)
$file = FileOpen($printerlist, 0)

While 1
    $line = FileReadLine($file)
    if @error = -1 then ExitLoop
    GuiCtrlSetData($printlist, $line1 & " |")
Wend

GUISetState(@SW_SHOW) ; display the GUI

Maybe there is a better way to do what I want or am I just doing it wrong?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I want to generate a list of available printers on a print server, then import this list into a combo box in an AutoIt GUI. The print server has a command that I can run from a command prompt at a windows workstation to generate the list. The command is:

If I run the command and redirect the output to a file:I get a test.txt file that reads as a single line of text in wordpad. ...

Take that output and look at it in a text reader that can display non printable chr's

You may have extra "new lines" that are feeding in??? (Yes, shot in the dark)

perhaps you could attach a sample of the text file?

Edited by everseeker

Everseeker

Share this post


Link to post
Share on other sites

Hi,

try this:

MsgBox(64, 'DOS', _getDOSOutput('set'))

Func _getDOSOutput($command)
    Local $text = '', $Pid = Run(@ComSpec & ' /c ' & $command, '', @SW_HIDE, 2 + 4)
    While 1
        $text &= StdoutRead($Pid, False, False)
        If @error Then ExitLoop
        Sleep(10)
    WEnd
    Return $text
EndFunc   ;==>_getDOSOutput

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Thanks for the suggestions. Before I read them this morning, I figured out a way to do what I wanted and now I have the combo lists populated properly.

Now the only thing I cannot figure out how to do is refresh the data once it is loaded. I think what I need to do is create custom functions that I can call over and over to refresh the lists, but I have no experience with that and I have not had much luck in my experiments. What I am doing for now, is simply restarting the entire script to reload the lists.

I'll post a new thread if I cannot get the functions to work.

Thanks

Cliff

Share this post


Link to post
Share on other sites

Could you describe what this does "MsgBox(64, 'DOS', _getDOSOutput('set'))

". What is the ('set') show in your msgbox?

Hi,

try this:

MsgBox(64, 'DOS', _getDOSOutput('set'))

Func _getDOSOutput($command)
    Local $text = '', $Pid = Run(@ComSpec & ' /c ' & $command, '', @SW_HIDE, 2 + 4)
    While 1
        $text &= StdoutRead($Pid, False, False)
        If @error Then ExitLoop
        Sleep(10)
    WEnd
    Return $text
EndFunc   ;==>_getDOSOutput

Mega

Thanks

CC

Share this post


Link to post
Share on other sites

Could you describe what this does "MsgBox(64, 'DOS', _getDOSOutput('set'))

". What is the ('set') show in your msgbox?

It does not work well with those extra parameters for StdOutRead in 3.2.10.0. 3.2.10.0 has the issues but the beta works so 3.2.10.0 has a bug with StdOut that was fixed in the beta. Set used by itself shows the environmental variables available. Try the below sample.

MsgBox(64, 'DOS', _getDOSOutput('set'))

Func _getDOSOutput($command)
    Local $text = '', $Pid = Run(@ComSpec & ' /c ' & $command, '', @SW_HIDE, 2 + 4)
    While 1
        $text &= StdoutRead($Pid)
        If @error Then ExitLoop
    WEnd
    Return $text
EndFunc   ;==>_getDOSOutput

The Msgbox should show the return value of _getDOSOutput('set').

:D

Share this post


Link to post
Share on other sites

Hi,

I'm always using latest beta. And you should add a sleep the loop Mhz, I guess.

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
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
Sign in to follow this  
Followers 0