Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Unexpected Result...Send scripts in same CMD


  • Please log in to reply
14 replies to this topic

#1 armoros

armoros

  • Active Members
  • PipPipPipPipPipPip
  • 503 posts

Posted 13 April 2012 - 06:27 PM

I am trying to create some scripts with cmd commands like this
Run(@ComSpec & ' /kipconfig/all ')
compile it to exes and running them .

But i want to make buttons in my gui and run the corresponding exe/command
what i would like to know if possible, is how to make these exe/commands to open in the same cmd window. (no in different instances of cmd)

The Unexpected Result in the title is because i made this script to open my 2 exe/commands
and made me reboot my pc...

WARNING do not run this script (it opens very fast lots of cmd windows)

AutoIt         
#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Local $Button_1, $Button_2, $msg #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 338, 221, 299, 132) $Button1 = GUICtrlCreateButton("ipconfig", 48, 128, 75, 25) $Button2 = GUICtrlCreateButton("netstat", 216, 128, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### asssdd() Func asssdd() While 1         $msg = GUIGetMsg()         Select             Case $msg = $GUI_EVENT_CLOSE                 ExitLoop             Case $msg = $Button_1                 Run('ipco.exe') ; Will Run ipco.exe that exist in the same folder as the script             Case $msg = $Button_2                Run('netstat.exe') ; Will Run netstat.exe that exist in the same folder as the script         EndSelect     WEnd EndFunc








#2 kylomas

kylomas

    FUBAR

  • MVPs
  • 2,885 posts

Posted 13 April 2012 - 06:32 PM

armoros,

Your variable names do NOT match...$Button_1 in the select stmt, but, $Button1 in the definition...

kylomas
  • armoros likes this

"Really?, How Do you know the're not random numbers?"

 

Forum Rules         Procedure for posting code

 

"A child educated only at school is an uneducated child."

    - George Santayana

 

"Never miss a good chance to shut up."

    - Will Rogers
 


#3 armoros

armoros

  • Active Members
  • PipPipPipPipPipPip
  • 503 posts

Posted 13 April 2012 - 06:41 PM

armoros,

Your variable names do NOT match...$Button_1 in the select stmt, but, $Button1 in the definition...

kylomas


Thank you Kylomas ur right.... ;)

but except my bad script is it possible to open different commands/scripts in same cmd window

#4 kylomas

kylomas

    FUBAR

  • MVPs
  • 2,885 posts

Posted 13 April 2012 - 06:44 PM

armoros,

You'll have to wait for someone with expertise to answer. I rarely, if ever, use the CMD window.

Good Luck,

kylomas
  • armoros likes this

"Really?, How Do you know the're not random numbers?"

 

Forum Rules         Procedure for posting code

 

"A child educated only at school is an uneducated child."

    - George Santayana

 

"Never miss a good chance to shut up."

    - Will Rogers
 


#5 armoros

armoros

  • Active Members
  • PipPipPipPipPipPip
  • 503 posts

Posted 13 April 2012 - 06:47 PM

armoros,

You'll have to wait for someone with expertise to answer. I rarely, if ever, use the CMD window.

Good Luck,

kylomas


Thank you my friend you were helpful...
I have an issue of passion with cmd ;)

#6 BrewManNH

BrewManNH

    באָבקעס מיט קודוצ׳ה

  • MVPs
  • 10,156 posts

Posted 13 April 2012 - 06:50 PM

Why are you creating separate exes for the different commands you want to run? Why not just run them directly from the main script, seeing as how the exes you're running are just AutoIt exes?

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 an XP machine, 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!

 

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 editorGUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.
GUIToolTip UDF Demo - Demo script to show how to use the GUIToolTip UDF to create and use customized tooltips. Latin Square password generator

 

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.


#7 armoros

armoros

  • Active Members
  • PipPipPipPipPipPip
  • 503 posts

Posted 13 April 2012 - 06:57 PM

Why are you creating separate exes for the different commands you want to run? Why not just run them directly from the main script, seeing as how the exes you're running are just AutoIt exes?


Thank you for the response BrewManNH, but i don't understand what you mean ...

#8 rodent1

rodent1

    Wayfarer

  • Active Members
  • Pip
  • 86 posts

Posted 13 April 2012 - 06:58 PM

It's possible, but you need 2 different scripts.
If you create a console script WITHOUT GUI and compile it with the option "Create CUI instead of GUI EXE", your compiled script, if run from the cmd box, will read from the cmd box and output to it. That compiled script could launch another autoit script with a GUI and wait for its disappearence or a command from it before it exits. That second (GUI) script has buttons and is compiled with the GUI option.
With this setup, the 2 scripts can talk to each other, communicate data, one can read the cmd box and write to it, it's the "puppet", the GUI one is the "puppet master".
  • armoros likes this

#9 BrewManNH

BrewManNH

    באָבקעס מיט קודוצ׳ה

  • MVPs
  • 10,156 posts

Posted 13 April 2012 - 07:12 PM

Thank you for the response BrewManNH, but i don't understand what you mean ...

Try this, compile it, then run the resulting exe and see what it does.

AutoIt         
#region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_UseX64=n #AutoIt3Wrapper_Change2CUI=y #endregion ;**** Directives created by AutoIt3Wrapper_GUI **** GUICreate("") $button = GUICtrlCreateButton(" IPConfig ", 20, 20) $button2 = GUICtrlCreateButton(" NetStat ", 20, 70) GUISetState() While 1     $msg = GUIGetMsg()     Switch $msg         Case -3             Exit         Case $button             _IPConfig()         Case $button2             _NetStat()     EndSwitch WEnd Func _IPConfig()     $PID = Run("ipconfig /all", "", @SW_HIDE, 8)     While ProcessExists($PID)         $line = StdoutRead($PID)         If @error Then ExitLoop         If $line <> "" Then ConsoleWrite($line & @CRLF)     WEnd EndFunc   ;==>_IPConfig Func _NetStat()     $PID = Run("netstat", "", @SW_HIDE, 8)     While ProcessExists($PID)         $line = StdoutRead($PID)         If @error Then ExitLoop         If $line <> "" Then ConsoleWrite($line & @CRLF)     WEnd EndFunc

This is just a quick demo and you can prettify it however you'd like, but it gives you the general idea of what I'm talking about.
  • armoros likes this

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 an XP machine, 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!

 

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 editorGUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.
GUIToolTip UDF Demo - Demo script to show how to use the GUIToolTip UDF to create and use customized tooltips. Latin Square password generator

 

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.


#10 kylomas

kylomas

    FUBAR

  • MVPs
  • 2,885 posts

Posted 13 April 2012 - 07:35 PM

armoros,

SLightly different from BrewmanNH but same concept (can't type as fast as the Brewman)

AutoIt         
#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <Constants.au3> Local $Button1, $Button2, $msg, $edit010 $Form1   = GUICreate("Network Properties", 400, 400) $Button1 = GUICtrlCreateButton("ipconfig",10,  10, 75, 25) $Button2 = GUICtrlCreateButton("netstat", 315, 10, 75, 25) $Edit010 = GUICtrlCreateEdit("", 10,40,380,300, $ES_AUTOVSCROLL + $WS_VSCROLL + $ws_hscroll + $es_readonly) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### asssdd() Func asssdd()     Local $rslt,$out     While 1             $msg = GUIGetMsg()             Select                 Case $msg = $GUI_EVENT_CLOSE                     ExitLoop                 Case $msg = $Button1                     $rslt = Run(@ComSpec & " /c ipconfig", @SystemDir, @SW_HIDE, $STDERR_MERGED + $STDOUT_CHILD) ; Will Run ipco.exe that exist in the same folder as the script                     While 1                         $out = StdoutRead($rslt)                         If @error then exitloop                         GUICtrlSetData($edit010,$out & @lf,1)                     WEnd                 Case $msg = $Button2                     $rslt = Run(@ComSpec & " /c netstat", @SystemDir, @SW_HIDE, $STDERR_MERGED + $STDOUT_CHILD) ; Will Run ipco.exe that exist in the same folder as the script                     While 1                         $out = StdoutRead($rslt)                         If @error then exitloop                         GUICtrlSetData($edit010,$out & @lf,1)                     WEnd             EndSelect     WEnd EndFunc


kylomas
  • armoros likes this

"Really?, How Do you know the're not random numbers?"

 

Forum Rules         Procedure for posting code

 

"A child educated only at school is an uneducated child."

    - George Santayana

 

"Never miss a good chance to shut up."

    - Will Rogers
 


#11 armoros

armoros

  • Active Members
  • PipPipPipPipPipPip
  • 503 posts

Posted 13 April 2012 - 07:52 PM

It's possible, but you need 2 different scripts.
If you create a console script WITHOUT GUI and compile it with the option "Create CUI instead of GUI EXE", your compiled script, i".

Try this, compile it, then run the resulting exe and see what it does.


This is just a quick demo and you can prettify it however you'd like, but it gives you the general idea of what I'm talking about.

armoros,

SLightly different from BrewmanNH but same concept (can't type as fast as the Brewman)


kylomas


1) Redont1 Thank you for the info you show me the path to try achieve what i want..

2) BrewManNH Thank you too for the guidance and the script but when i compile it, opens the gui but nothing else happens .
ill test it more.

3) Kylomas thank you again its nice your script i had this in my mind after a simillar script from user Country73 here

Thank you all for the help guys . Now i know more ;)

#12 BrewManNH

BrewManNH

    באָבקעס מיט קודוצ׳ה

  • MVPs
  • 10,156 posts

Posted 13 April 2012 - 08:14 PM

2) BrewManNH Thank you too for the guidance and the script but when i compile it, opens the gui but nothing else happens .
ill test it more.

Did you actually press one of the buttons? Because it will display the results of that command in the command window when you do. Although I like kylomas' idea of using an edit box to display the information, much cleaner.

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 an XP machine, 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!

 

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 editorGUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.
GUIToolTip UDF Demo - Demo script to show how to use the GUIToolTip UDF to create and use customized tooltips. Latin Square password generator

 

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.


#13 kylomas

kylomas

    FUBAR

  • MVPs
  • 2,885 posts

Posted 13 April 2012 - 08:29 PM

armoros,

Something else that I am working on broke my brain so I've been goofing around with this. Here's a more complete way to do this.

AutoIt         
; example of using stdout with network commands #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <Constants.au3> #include <StaticConstants.au3> Local $Gui010  = GUICreate("Network Properties", 800, 600) Local $Button1 = GUICtrlCreateButton("IPCONFIG",10,  10, 75, 25) Local $Button2 = GUICtrlCreateButton("NETSTAT", 90, 10, 75, 25) Local $clear   = GUICtrlCreateButton("Clear Display", 700, 10, 90, 25)      GUICtrlSetBkColor($clear,0xff0000)      GUICtrlSetFont($clear,8.5,800,default,'times new roman')                  GUICtrlCreateLabel("PARM = ",200,15,75,25) Local $parm    = GUICtrlCreateEdit('',250,10,75,25,$ss_sunken)      GUICtrlSetFont($parm,12,800)      GUICtrlSetState($parm,$gui_focus) Local $Edit010 = GUICtrlCreateEdit("", 10,40,780,550, $ES_AUTOVSCROLL + $WS_VSCROLL + $ws_hscroll + $es_readonly)                  GUICtrlSetFont(-1,8.5,800,default,'courier new') GUISetState(@SW_SHOW) net_properties() Func net_properties()  Local $rslt,$out  While 1    $msg = GUIGetMsg()    Select     Case $msg = $GUI_EVENT_CLOSE      ExitLoop     Case $msg = $Button1      $rslt = Run(@ComSpec & " /c ipconfig " & GUICtrlRead($parm), @SystemDir, @SW_HIDE, $STDERR_MERGED + $STDOUT_CHILD) ; Will Run ipco.exe that exist in the same folder as the script      While 1       $out = StdoutRead($rslt)       If @error then exitloop       GUICtrlSetData($edit010,$out & @lf,1)      WEnd     Case $msg = $Button2      $rslt = Run(@ComSpec & " /c netstat " & GUICtrlRead($parm), @SystemDir, @SW_HIDE, $STDERR_MERGED + $STDOUT_CHILD) ; Will Run ipco.exe that exist in the same folder as the script      While 1       $out = StdoutRead($rslt)       If @error then exitloop       GUICtrlSetData($edit010,$out & @lf,1)      WEnd     Case $msg = $clear      GUICtrlSetData($edit010,"")    EndSelect  WEnd EndFunc


kylomas
  • armoros likes this

"Really?, How Do you know the're not random numbers?"

 

Forum Rules         Procedure for posting code

 

"A child educated only at school is an uneducated child."

    - George Santayana

 

"Never miss a good chance to shut up."

    - Will Rogers
 


#14 armoros

armoros

  • Active Members
  • PipPipPipPipPipPip
  • 503 posts

Posted 13 April 2012 - 09:04 PM

Did you actually press one of the buttons? Because it will display the results of that command in the command window when you do. Although I like kylomas' idea of using an edit box to display the information, much cleaner.


Yes i did it compile it and run it but when i press the buttons nothing happens, (i am on a xp sp3 )


armoros,

Something else that I am working on broke my brain so I've been goofing around with this. Here's a more complete way to do this.


kylomas


Yeah very nice script it gives me an idea.....

#15 armoros

armoros

  • Active Members
  • PipPipPipPipPipPip
  • 503 posts

Posted 14 April 2012 - 09:32 AM

Try this, compile it, then run the resulting exe and see what it does.

#region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_UseX64=n #AutoIt3Wrapper_Change2CUI=y #endregion ;**** Directives created by AutoIt3Wrapper_GUI **** GUICreate("")

This is just a quick demo and you can prettify it however you'd like, but it gives you the general idea of what I'm talking about.

I am sorry BrewManNH it was my fault your script is exactly what i wanted but i was so blind that i didn't notice ;)

the
AutoIt3Wrapper_Change2CUI=y


Yes it works perfect
Thank you very much.... :)

Thank you also for your permission to use it..

Thank you all guys Kylomas your 2 script is super..

I will use all

Edited by armoros, 14 April 2012 - 11:43 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users