olmanRvr

write return value of exe call to text file

14 posts in this topic

I have a compiled script :-timeStampSecs.exe which returns timestamp in seconds. I call it in FileWrite to write the time stamp in a text file.But it writes some other values instead of the timestamp. Please help.

thanks

olmar

The script is below:-

$kNum=run("timeStampSecs.exe","",1); also tried with flags 2,4,8,10
$hFile=FileOpen("timeStamp.txt",2)
FileWrite($hFile,"the key is: "&$kNum)
FileClose("$hFile")

;Code of thetimeStampSecs.exe:-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#include <Date.au3>

Func secFromEpoch()
Local $ts=_DateDiff( "s","1970/01/01 00:00:00",_NowCalc())
    $ts=String($ts)
    ConsoleWrite("timeStamp is: "&$ts&@CRLF)
        Return $ts
EndFunc
secFromEpoch()

 

Share this post


Link to post
Share on other sites



olmanRvr,

Look at the help file for run.  RUN returns the PID if successful.  If you want to write the time stamp to a file you will have to do that in the script that calculates it.  You can pass in a file name as a command line parameter if you wish.

kylomas


Forum Rules         Procedure for posting code

Share this post


Link to post
Share on other sites

Hi, Thanks for the quick reply.Let me try your suggestion .Will let you know

olmar

Share this post


Link to post
Share on other sites

olmanRvr,

Or you can read the return stream of the process like this:

#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>

Local $iPID = Run("timeStampSecs.exe", "", @SW_HIDE, $STDOUT_CHILD + $STDERR_CHILD)
Local $sOutput
While 1
    $sTemp = StdoutRead($iPID)
    $sTemp &= StderrRead($iPID)
    ; Exit the loop if the process closes or StdoutRead returns an error.
    If @error Then
        ExitLoop
    Else
        $sOutput &= $sTemp
    EndIf
    Sleep(10)
WEnd
MsgBox($MB_SYSTEMMODAL, "Stdout Read:", $sOutput)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post


Link to post
Share on other sites
FileClose("$hFile")

should rather be 

FileClose($hFile)

just a typo though.

When calling command line executables I quite often have more succes using:

Run(@ComSpec & " /c " & ...)

 

Share this post


Link to post
Share on other sites

Instead of Run used RunWait as per Jos .Same issue--- writing PID numbers in place of the time stamp as wanted.Also removes quotes from fileclose  like "$hFile"-->$hFile but doesn't help.

Working on reading the return stream(as per Melba23's suggestion).

 

see you.........

Share this post


Link to post
Share on other sites

Read stream of  run call to timeStampSecs.exe .But still getting blank output(in consoleWrite.See code below:--

#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>

Func readStream()
            Local $iPID = Run("timeStampSecs.exe", "", @SW_HIDE, $STDOUT_CHILD + $STDERR_CHILD)
        Local $sOutput
        While 1
            $sTemp = StdoutRead($iPID)
            $sTemp &= StderrRead($iPID)
            ; Exit the loop if the process closes or StdoutRead returns an error.
            If @error Then
                ExitLoop
            Else
                $sOutput &= $sTemp
            EndIf
            Sleep(10)
        WEnd
        MsgBox($MB_SYSTEMMODAL, "Stdout Read:", $sOutput)
        ConsoleWrite("ts is: "&$sOutput&@CRLF)
        Return $sOutput
EndFunc
readStream()

 

Share this post


Link to post
Share on other sites
18 minutes ago, olmanRvr said:

 

Instead of Run used RunWait as per Jos .Same issue--- writing PID numbers

 

Nah, RunWait() returns the Returncode of the shelled program. ;)

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#10 ·  Posted

olmanRvr,

The  StdoutRead code worked for me with a compiled version of the script you posted in the OP, as did Jos' suggestion.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post


Link to post
Share on other sites

#11 ·  Posted

olmanRvr,

Works perfectly for me like this (M23 code modified)...

#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>

Local $iPID = Run(@scriptdir & "\timeStampSecs.exe", "", @SW_HIDE, $STDOUT_CHILD + $STDERR_CHILD)
Local $sOutput
While 1
    $sOutput &= StdoutRead($iPID)
    If @error Then ExitLoop
    Sleep(10)
WEnd
MsgBox($MB_SYSTEMMODAL, "Stdout Read:", $sOutput)

kylomas


Forum Rules         Procedure for posting code

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Hi kylomas,

Tried the code  you have shown.Yes, it is showing the timestamp in  a GUI window.Problem arises when I  add  the following line:-

ConsoleWrite("value is: "&$sOutput&@CRLF)

ConsoleWrite fails to write the value.Same issue occurs when writing the value of  $sOutput to a text file.Weird thing is if I replace the 

timeStampSecs.exe with  genKeyNum.exe it works fine !! Any idea, anyone please?

example below:

;Only difference to the previous function is that another  exe file is invoked
Func runExegenKeyNum();the exe fetches the physical drive number
        Local $iPID = Run(@scriptdir & "\genKeyNum.exe", "", @SW_HIDE, $STDOUT_CHILD + $STDERR_CHILD)
        Local $sOutput
        While 1
            $sOutput &= StdoutRead($iPID)
            If @error Then ExitLoop
            Sleep(10)
        WEnd
        MsgBox($MB_SYSTEMMODAL, "Stdout Read:", $sOutput)
        ConsoleWrite("value is; "&$sOutput&@CRLF)
        Return $sOutput
EndFunc
 runExegenKeyNum()
 ;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 ;code for genKeyNum.exe
 
 Func gtSrNo()
        $wbemFlagReturnImmediately = 0x10
        $wbemFlagForwardOnly = 0x20
        $colItems = ""
        $strComputer = "localhost"
        Global $Output=""
        $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
        $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive", "WQL", _
        $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    For $oItm In $colItems
        $Output = $Output & $oItm.SerialNumber & @CRLF
    Next
        ConsoleWrite($Output&@CRLF)
    Return $Output;$Output is the serial; number
EndFunc

 

Edited by olmanRvr
typho

Share this post


Link to post
Share on other sites

#13 ·  Posted

Sideways offer: why not including the various function in the main script instead of invoking them compiled as as many executables?


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#14 ·  Posted

Hi,

I would hard code these values(Hd srnum&timestamp) into the code for each user, basically to bind it to a single machine for a predefined period.Hence in the last moment, after user clicks download button,these values are fetched and incorporated into the script & then compiled .Which will, then be downloaded.

But thanks for your reply

olmar

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

  • Similar Content

    • kneze
      search value in text file
      By kneze
      Hi all,
      i would like to enter a vlaue to Inputbox 1 an press button1. Script should search value in a text file and put value after "; " to Inputbox 2.
      #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.2 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <file.au3> $Form1 = GUICreate("Form1", 257, 119, 192, 124) $Input1 = GUICtrlCreateInput("Input1", 15, 35, 121, 21) $Input2 = GUICtrlCreateInput("Input2", 15, 60, 121, 21) $Button1 = GUICtrlCreateButton("Button1", 145, 35, 75, 25) GUISetState(@SW_SHOW) $iLines = _FileCountLines(@ScriptDir & "\data.txt") ;MsgBox(0, "Char read:", $ilines) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 EndSwitch WEnd can anyone help?
      data.txt
    • caramen
      MsgBox 4 return value ?
      By caramen
      Hello guy got some trouble in this easy script
       
      Case $BoutonWhrite1 $Case1 = MsgBox (4,"Are you sure ?" ,"Reg key gonna be changed." ) While 1 If $Case1 = "No" Then ConsoleWrite(">Case -1 Started" & @CRLF) ExitLoop EndIf $InputType = InputBox ("Value Type ?", 'Type of key to write: "REG_SZ", "REG_MULTI_SZ", "REG_EXPAND_SZ", "REG_DWORD", "REG_QWORD", or "REG_BINARY".' ) ;~ RegWrite (""&Reg1,""&$RegName1,""&$InputType, ""&$RegValue1) ExitLoop WEnd I tryed
      If $case1 = 1
      If $case1 = -1
      If $case1 = "No"
       
      What is the returned value by the msg box YES or NO ?
       
      The script is going wrong about the final purpose (Whrite a Registry key if the Script user unswer YES ) But dont take attention i am gonna corect after get the returned value xD it was for testing. 
    • OMGWTFLOLBBQ
      Text to Array
      By OMGWTFLOLBBQ
      Hello!
       I've been going through all of the help files and examples, but I feel lost. I can't seem to find what I need. Essentially, what I'm doing is simple(in my head).
      Create a file based on the information needed, select a line in that file, then put that line back in DOS. My code is below, I know it's messy, but I'll take the heat if you can help.
       
      ;BitlockerUpdate ;2016.05.24 HotKeySet("{ESC}", "Terminate") Run("C:\Windows\System32\CMD.exe") ;open command prompt Sleep(500) ;sleep half second if ProcessExists("cmd.exe") Then winactivate("Administrator: C:\Windows\System32\CMD.exe") ;refocus command prompt Send("C:") Send("{ENTER}") send("CD{SPACE}%windir%\sysnative\") send("{ENTER}") EndIf ;create file with Bitlocker Protectors Send("manage-bde.exe{SPACE}-protectors{SPACE}-get{space}c:{space}>{Space}%userprofile%\Desktop\protectors.txt") ;send code "manage-bde -protectors -get c: > %userprofile%\Desktop\protectors.txt" Send("{ENTER}") ;send enter key to create text file on desktop with protectors Sleep(1000) ;sleep one second(1s) ;edit txt file/create array, pull line and paste into new file, copy text then paste into cmd window below ;update data if ProcessExists("cmd.exe") Then winactivate("Administrator: C:\Windows\System32\CMD.exe") ;refocus command prompt Send("manage-bde.exe{SPACE}-protectors{SPACE}-adbackup{SPACE}c:{SPACE}-id{SPACE}{COPIEDINFORMATIONGOESHERE}") Send("{ENTER}") ;don't forget to delete temp file if you create one created. EndIf ;remove files if ProcessExists("cmd.exe") Then winactivate("Administrator: C:\Windows\System32\CMD.exe") ;refocus command prompt Send("DEL{SPACE}%userprofile%\Desktop\protectors.txt") ;send code to delete protectors.txt Send("{ENTER}") ;don't forget to delete temp file if you create one created. EndIf MsgBox(0,"Done","Copy and upload are done. Please check Computer in AD.") Func Terminate() Exit 0 EndFunc  
      The protectors.txt file looks like this:
      BitLocker Drive Encryption: Configuration Tool version 6.1.7601 Copyright (C) Microsoft Corporation. All rights reserved. Volume C: [OSDisk] All Key Protectors TPM: ID: {0000000-0000-0000-0000-0000000} Numerical Password: ID: {1000000-1000-1000-1000-1000000} Password: 000000-000000-000000-000000-000000-000000-000000 Data Recovery Agent (Certificate Based): ID: {2000000-2000-2000-2000-2000000} Certificate Thumbprint: 1111111a1aa1a1aa1a1a1a1aaaaaa1aaa1 I would specifically need the line after Numerical Password. 
      Original line:      ID: {1000000-1000-1000-1000-1000000}
      Needed information: -ID: {1000000-1000-1000-1000-1000000}
       
      I apologize in advance for inconveniencing anyone with my silly issues. Hopefully this can stand as a great learning experience for both me and anyone else looking.
       
    • CaptainSparky
      StringLeft help!
      By CaptainSparky
      Hello good friends of Autoit, so I am making a chatbot using Autoit but I got stuck on this part:
      I already have stringright($var,stringlen($var) - stringlen(" = ") - StringInStr($var," = ") + 1) the program is made to read a text file and extract from a specific line the text after = and before =, for example:
      example line of text file: something = okay this is a text
      and I needed to extract the right part (which I already have done) and the left part (which I need help with) so how can you make stringleft to get all text before "="?
      Thanks in advance.
      Here's my code if you need it:
      #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <File.au3> #include <Misc.au3> #Include <Array.au3> Global $BrainLocation = @ScriptDir & "\brain.txt" Global $FormName = "Project Lisa" Global $ReatInput = "null" Global $Memory[100] Global $BrainLineCount = 1 Global $Random[100] Global $RandomCount = 0 Global $SplitInput[100] Global $BrainCount = 0 Loader() Func Loader() Global $Form = GUICreate($FormName, 417, 279, 192, 124) Global $Output = GUICtrlCreateEdit("", 8, 8, 401, 225, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_HSCROLL),0) Global $Input = GUICtrlCreateInput("", 104, 240, 209, 21) GUISetState(@SW_SHOW) ControlFocus($FormName,"",$input) HotKeySet("{ENTER}","SendText") Main() EndFunc func Main() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd EndFunc Func SendText() $ReatInput = GUICtrlRead($Input) GUICtrlSetData($Output,@CRLF & "You > " & $ReatInput,1) CreateRandoms() EndFunc Func CreateRandoms() While $RandomCount <> 100 $Random[$RandomCount] = Random(1,$RandomCount,1) $RandomCount += 1 WEnd $RandomCount = 0 BrainLoader() EndFunc Func BrainLoader() $ReatBrain = FileReadLine($Brainlocation,$BrainLineCount) $BrainStringRight = stringright($ReatBrain,stringlen($ReatBrain) - stringlen(" = ") - StringInStr($ReatBrain," = ") + 1) MsgBox(0,"",$Brainstringright) $BrainStringLenRight = Stringlen($brainstringright) MsgBox(0,"",$Brainstringright) $BrainActualString = 0 + $BrainStringLenRight - 10 MsgBox(0,"",$BrainActualString) $test = StringLeft($ReatBrain,$brainactualstring) MsgBox(0,"",$test) $BrainSplitedStrings = StringSplit($BrainStringRight,",") If $BrainSplitedStrings[1] <> "" Then $_1 = "true" $BrainCount += 1 EndIf If $ReatInput = $BrainActualString Then $BrainRan = Random(1,$braincount) GUICtrlSetData($output,@CRLF & "Lisa > " & $BrainSplitedStrings[$BrainRan],1) $BrainLineCount = 1 Main() Else main() EndIf $BrainLineCount += 1 BrainLoader() EndFunc
    • jgq85
      Read text file and close windows containing any of strings from each line?
      By jgq85
      Hi I'm looking to start a new (what I think will be simple) program. 
      Basically I want to just have a text file that sits in a location, say, C:blockwindows.txt.
      For AutoIt I just want it to open and begin auto-closing any windows that contain the string that is put in each line within that c:blockwindows.txt.
      So the C:blockwindows.txt may contain these strings
      "some string here test"
      "another string here"
      "yet another string".
      So what AutoIt would do, is constantly be monitoring for any openings of windows on the computer that contains any of those strings, whether it's at the beginning or end or whereever in the Window title.
      These windows could open up at any time of the day.
      Here's what I've got so far from research, just having a challenge determining whether it's the right approach, and ultimately, figuring out how to piece it together.
      - I do not know what window MatchMode to use based on the strings read from the text file to determine if the string matches that of what's in the title. I could make an exact match given that I do know what prefix and suffix comes before/after the string variable if needed. 
      $FilePath = "C:blockedwindows.txt" $FileRead = FileRead($FilePath ) $WindowName = StringSplit($FileRead , @CRLF, 1) For $i =1 To $WindowName[0] WinClose ($WindowName[$i]) Next   Something like this could work I'm just worried about CPU usage. It goes about 25% of the CPU. But if I add a sleep(1000) after WinClose, it remains at 0% CPU.