Jump to content

Recommended Posts

Posted

no, with /c it closes the process before it finishes so IT determined to use /k instead to keep the window open, but that won't let the process finish for the script to continue past runwait (but it does print with the /k replacement). :/

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

  • Developers
Posted

I think we are saying the same thing and /k isn't really a solution but simply acts as a blocking function.

I will do some testing with RunWait() and LPR to see if I can replicate your issue.

You could try yourself to create a Loop after the RunWait() command that loops until ProcessExists("lpr.exe") is false.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted (edited)

you mean something like

RunWait(@ComSpec & ' /c lpr -S "' & $ipad & '" -P raw -o l -d "' & $flad & '"')
    Do
        sleep(10)
    Until (ProcessExists("lpr.exe") = 0)
    Return

*edit*

With the /c method, cmd closes, nothing prints, then the file input clears as the script moves on

with the /k method, cmd stays open, the file prints and the file input does not clear until the cmd window is closed.

haven't tried this the loop, but I'm not understanding what that's going to show me

full script (I only changed the calling main() to returns to avoid recursion and added a clear file input upon return):

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=V:\AutoIt\Scripts\IP Print.exe
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Add_Constants=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
; *** Start added by AutoIt3Wrapper ***
#include <GUIConstantsEx.au3>
; *** End added by AutoIt3Wrapper ***
#include <GuiConstants.au3>
#include <Array.au3>
#include <WindowsConstants.au3>
#include <iNet.au3>

$x = 1
$i = 0
Global $ip
Global $ipen
Global $ipme
Global $ipin
Global $ftpr
Global $prin
Global $ip[$x]
Global $lbl1 = ""

If Not FileExists(@ScriptDir & "\printip.ini") Then
    IniWrite(@ScriptDir & "\printip.ini","ips",1,"172.16.60.17")
    IniWrite(@ScriptDir & "\printip.ini","ips",2,"172.16.60.18")
    IniWrite(@ScriptDir & "\printip.ini","ips",3,"172.16.60.19")
    IniWrite(@ScriptDir & "\printip.ini","ips",4,"172.16.60.20")
    IniWrite(@ScriptDir & "\printip.ini","ips",5,"Enter IP")
EndIf

$ip = IniReadSection(@ScriptDir & "\printip.ini", "ips")

GUICreate("IP Print", 250, 120, -1, -1, -1, $WS_EX_ACCEPTFILES)
$ipen = GUICtrlCreateCombo("", 1, 50)
GUICtrlCreateLabel("Select IP", 1, 32, 45, 15)

For $x = 1 To UBound($ip) - 1
    If $ip[$x][1] <> "Enter IP" Then
        GUICtrlSetData($ipen, $ip[$x][1] & "|")
    EndIf
Next

$ipme = GUICtrlCreateInput("Enter IP", 1, 3, 100, 20)
$ipin = GUICtrlCreateButton("Save IP", 105, 1)
$ftpr = GUICtrlCreateInput("", 1, 97, 100, 20)
GUICtrlSetState($ftpr, $GUI_DROPACCEPTED)
$prin = GUICtrlCreateButton("Print", 105, 94)
GUICtrlCreateLabel("Drag File Here", 1, 77, 75, 15)
$ptnm = GUICtrlCreateLabel("Printer Name", 58, 32, 105, 15)

GUISetState(@SW_SHOW)

main()

Func main()
    TCPStartup()

    While 1
        $msg = GUIGetMsg()

        $lbl = GUICtrlRead($ipen)
        If $lbl <> $lbl1 Then
            $ptr = _TCPIpToName($lbl, 1)
            If IsArray($ptr) Then
            ;   _ArrayDisplay($ptr)
            ;    MsgBox(0, "", $lbl & " " & $ptr[1])
                GUICtrlSetData($ptnm, $ptr[$ptr[0]])
            EndIf
            $lbl1 = $lbl
        EndIf

        If $msg = $ipin Then
            $i=0
            Do
                $i += 1
                $chk = IniRead(@ScriptDir & "\printip.ini", "ips", $i, "")
            Until $chk = ""
            $nwip = GUICtrlRead($ipme)
            IniWrite(@ScriptDir & "\printip.ini", "ips", $i, $nwip)
            GUICtrlSetData($ipme,"Enter IP")

            GUICtrlSetData($ipen, "")

            $ip = IniReadSection(@ScriptDir & "\printip.ini", "ips")

            For $x = 1 To UBound($ip) - 1
                If $ip[$x][1] <> "Enter IP" Then
                    GUICtrlSetData($ipen, $ip[$x][1] & "|")
                EndIf
            Next

        ElseIf $msg = $prin Then

            print()
            GUICtrlSetData($ftpr,"")

        ElseIf $msg = $GUI_EVENT_CLOSE Then
            GUIDelete()
            Exit (1)

        EndIf

    WEnd

EndFunc   ;==>main

Func print()

    $ipad = GUICtrlRead($ipen)
    $flad = GUICtrlRead($ftpr)

    If $ipad = "" or $ipad = "Enter IP" Then
        MsgBox(0, "Error", "No IP Selected", 10)
        Return
    EndIf

    If $flad = "" Then
        MsgBox(0, "Error", "No File Selected", 10)
        Return
    EndIf

    RunWait(@ComSpec & ' /c lpr -S "' & $ipad & '" -P raw -o l -d "' & $flad & '"')
    Return

EndFunc   ;==>print

*edit 2*

thinking about it more, if lpr.exe shows up as a 2nd process launched by cmd, then maybe something like this would work

Run(@ComSpec & ' /k lpr -S "' & $ipad & '" -P raw -o l -d "' & $flad & '"')
    Do
        sleep(10)
    Until (ProcessExists("lpr.exe") = 0)
    Return

I'll have the IT guy test it out tomorrow.

Edited by kaotkbliss

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

  • Solution
Posted

ok, got it working :) thank you for all your help!

added a flag for lpr.exe to see if it's running

then did run instead of runwait with the /k command

After that is a loop to pause the script, first until lpr is running (then change the flag to 1)

then check to see if flag is 1 and lpr is no longer running

when this condition is met, it closes cmd and continues on with the script :)

(Also found out that sometimes it needs to run as admin (sometimes not)) so I added #requireadmin

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=V:\AutoIt\Scripts\IP Print.exe
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Add_Constants=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
; *** Start added by AutoIt3Wrapper ***
#include <GUIConstantsEx.au3>
; *** End added by AutoIt3Wrapper ***
#include <GuiConstants.au3>
#include <Array.au3>
#include <WindowsConstants.au3>
#include <iNet.au3>


$x = 1
$i = 0
Global $ip
Global $ipen
Global $ipme
Global $ipin
Global $ftpr
Global $prin
Global $ip[$x]
Global $lbl1 = ""
Global $lpr = 0

If Not FileExists(@ScriptDir & "\printip.ini") Then
    IniWrite(@ScriptDir & "\printip.ini","ips",1,"172.16.60.17")
    IniWrite(@ScriptDir & "\printip.ini","ips",2,"172.16.60.18")
    IniWrite(@ScriptDir & "\printip.ini","ips",3,"172.16.60.19")
    IniWrite(@ScriptDir & "\printip.ini","ips",4,"172.16.60.20")
    IniWrite(@ScriptDir & "\printip.ini","ips",5,"Enter IP")
EndIf

$ip = IniReadSection(@ScriptDir & "\printip.ini", "ips")

GUICreate("IP Print", 250, 120, -1, -1, -1, $WS_EX_ACCEPTFILES)
$ipen = GUICtrlCreateCombo("", 1, 50)
GUICtrlCreateLabel("Select IP", 1, 32, 45, 15)

For $x = 1 To UBound($ip) - 1
    If $ip[$x][1] <> "Enter IP" Then
        GUICtrlSetData($ipen, $ip[$x][1] & "|")
    EndIf
Next

$ipme = GUICtrlCreateInput("Enter IP", 1, 3, 100, 20)
$ipin = GUICtrlCreateButton("Save IP", 105, 1)
$ftpr = GUICtrlCreateInput("", 1, 97, 100, 20)
GUICtrlSetState($ftpr, $GUI_DROPACCEPTED)
$prin = GUICtrlCreateButton("Print", 105, 94)
GUICtrlCreateLabel("Drag File Here", 1, 77, 75, 15)
$ptnm = GUICtrlCreateLabel("Printer Name", 58, 32, 105, 15)

GUISetState(@SW_SHOW)

main()

Func main()
    TCPStartup()

    While 1
        $msg = GUIGetMsg()

        $lbl = GUICtrlRead($ipen)
        If $lbl <> $lbl1 Then
            $ptr = _TCPIpToName($lbl, 1)
            If IsArray($ptr) Then
            ;   _ArrayDisplay($ptr)
            ;    MsgBox(0, "", $lbl & " " & $ptr[1])
                GUICtrlSetData($ptnm, $ptr[$ptr[0]])
            EndIf
            $lbl1 = $lbl
        EndIf

        If $msg = $ipin Then
            $i=0
            Do
                $i += 1
                $chk = IniRead(@ScriptDir & "\printip.ini", "ips", $i, "")
            Until $chk = ""
            $nwip = GUICtrlRead($ipme)
            IniWrite(@ScriptDir & "\printip.ini", "ips", $i, $nwip)
            GUICtrlSetData($ipme,"Enter IP")

            GUICtrlSetData($ipen, "")

            $ip = IniReadSection(@ScriptDir & "\printip.ini", "ips")

            For $x = 1 To UBound($ip) - 1
                If $ip[$x][1] <> "Enter IP" Then
                    GUICtrlSetData($ipen, $ip[$x][1] & "|")
                EndIf
            Next

        ElseIf $msg = $prin Then

            print()
            GUICtrlSetData($ftpr,"")

        ElseIf $msg = $GUI_EVENT_CLOSE Then
            GUIDelete()
            Exit (1)

        EndIf

    WEnd

EndFunc   ;==>main

Func print()

    $ipad = GUICtrlRead($ipen)
    $flad = GUICtrlRead($ftpr)

    If $ipad = "" or $ipad = "Enter IP" Then
        MsgBox(0, "Error", "No IP Selected", 10)
        Return
    EndIf

    If $flad = "" Then
        MsgBox(0, "Error", "No File Selected", 10)
        Return
    EndIf

    Run(@ComSpec & ' /k lpr -S "' & $ipad & '" -P raw -o l -d "' & $flad & '"')
    Do
        If ProcessExists("lpr.exe") Then
            $lpr = 1
        EndIf
        sleep(10)
    Until (ProcessExists("lpr.exe") = 0 and $lpr = 1)
    $lpr = 0
    ProcessClose("cmd.exe")
    Return

EndFunc   ;==>print

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...