AutoIt Forums: Shell and RunEx - AutoIt Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Shell and RunEx Rate Topic: -----

#1 Guest_Guidosoft_*

  • Group: Guests

Posted 25 February 2005 - 04:29 PM

I know it's simple but it's cool so I just post it cause its not worth putting in an include or anywhere else.

[ code='text' ]    ( Popup )
Func Shell($ShellCommand);Runs a MS-DOS command.    Run(@ComSpec & " /C " & $ShellCommand,"",@SW_HIDE) EndFunc Func RunEx($File);Runs a file.    Run(@ComSpec & " /C start " & $File,"",@SW_HIDE) EndFunc


I just learned what @ComSpec is for so I got excited, don't spoil my fun.

#2 User is offline   sPeziFisH 

  • Member
  • Pip
  • Group: Full Members
  • Posts: 49
  • Joined: 22-September 04

Posted 25 February 2005 - 05:19 PM

I will use Shell(format c:) if time has come :)

#3 Guest_brammeleman_*

  • Group: Guests

Posted 27 February 2005 - 10:54 PM

I just made a function to run a shell command and grab the output. It comes with a modified version of _TempFile:
[ code='text' ]    ( ExpandCollapse - Popup )
; ---------------------------------------------------------------------------- ; ; AutoIt Version: 3.1.0 ; Author:         B. Daams <brammeleman@brammeleman.org> ; ; Script Function: ;                Execute a single DOS command and return stdout ; ; Example: ;                Msgbox(4096, "Output of 'ls' on a remote host:", _ShellExec("c:\progra~1\putty\plink.exe host ls")) ; ---------------------------------------------------------------------------- Func _ShellExec($cmd)     $batchtemp = _TempFile2("bat")     $resulttemp = _TempFile2("txt") ; add " > $resulttemp" to $cmd     $cmd = $cmd & "> " & $resulttemp ; write $cmd to $batchtemp     $fh = FileOpen ($batchtemp,2)     If $fh = -1 Then         MsgBox(0, "Error", "Unable to open temporary batch file for writing.")         Exit     EndIf     FileWrite($fh, $cmd)     FileClose($fh) ; run $batchtemp     RunWait($batchtemp, @TempDir, @SW_HIDE)      ; read $resulttemp to $returnval     $fh = FileOpen($resulttemp, 0) ; Check if file opened for reading OK     If $fh = -1 Then         MsgBox(0, "Error", "Unable to open result file.")         Exit     EndIf ; Read in lines of text until the EOF is reached     $returnval = ""     While 1         $returnval = $returnval & @LF & FileReadLine($fh)         If @error = -1 Then ExitLoop     Wend ; clean up the mess     FileDelete($batchtemp)     FileDelete($resulttemp)          return $returnval EndFunc Exit Func _TempFile2($ext = "tmp") ; slightly modified version of UDF _TempFile ; this function accepts an optional argument $ext which ; allows you to specify the file type for the temporary ; file     Local $s_TempName          Do         $s_TempName = "~"         While StringLen($s_TempName) < 8          $s_TempName = $s_TempName & Chr(Round(Random(97, 122), 0))         Wend         $s_TempName = @TempDir & "\" & $s_TempName & "." & $ext     Until Not FileExists($s_TempName)     Return ($s_TempName) EndFunc

This post has been edited by brammeleman: 10 April 2005 - 10:07 AM


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users