fopetesl

Problems running Command Line commands

3 posts in this topic

#1 ·  Posted (edited)

I have problems running both Bat files and Command line instructions.

This function hopefully shows what I have tried so far

Global $fFileToCreate = "", $DOS
ScanFilm($fFileToCreate)
Func ScanFilm($fFileToCreate)
  MsgBox($MB_SYSTEMMODAL, "Scanning Status", $fFileToCreate)
;  $DOS = Run(@ComSpec & " /c " & "scan.bat" & @CRLF, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
  $DOS = Run(@ComSpec & " /k " & "ncat 192.168.1.6 80 <scant.txt >scanrep", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
;  $DOS = _RunDOS("ncat 192.168.1.6 80 <scant.txt >scanrep")
ProcessWaitClose($DOS)
$Message = StdoutRead($DOS)
MsgBox($MB_SYSTEMMODAL, "Stdout Read:", $Message)
Endfunc

My first attempt running scan.bat reveals a bug in cmd.exe where the result of

echo !SR | ncat 192.168.1.6 80 > scanrep

is

C:\S3_GUI\ncat>scan.bat

C:\S3_GUI\ncat>echo scant.txt   | ncat 192.168.1.6 80  1>scanrep
Ncat: .

C:\S3_GUI\ncat>

note the added '1' which then throws the error, (when client is connected), "File or directory not found" so the command fails.  This has been run on four different computers running Windows 7 with same result.

Next using Run() seems to truncate the command so $DOS reads:

Std_Out_Read.jpg

Using _RunDOS() doesn't throw any error but MsgBox() is empty.

 

 

 

 

 

 

Std_Out_Read.jpg

Std_Out_Read.jpg

Edited by fopetesl
too many images again!

The most powerful number in the Universe.  Zero.

Share this post


Link to post
Share on other sites



#2 ·  Posted

5 minutes ago, fopetesl said:

My first attempt running scan.bat reveals a bug in cmd.exe where the result of

note the added '1' which then throws the error

Don't think this is a bug but merely telling you at the STDOUT (1) output goes to the file. 

7 minutes ago, fopetesl said:

Next using Run() seems to truncate the command so $DOS reads:

Which RUN command is that as the current active Run()m command pipes the STDOUT to a file it is expected that only the DOS prompt is returned?

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

#3 ·  Posted

2 minutes ago, Jos said:

Don't think this is a bug but merely telling you at the STDOUT (1) output goes to the file. 

Which RUN command is that as the current active Run()m command pipes the STDOUT to a file it is expected that only the DOS prompt is returned?

Jos

I cannot argue with your logic regarding (1) output except when 'live' it fails with the error as stated.

I clearly have misunderstood StdOutRead() then. I'll try and pay more attention to F1 :)

 


The most powerful number in the Universe.  Zero.

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

    • fopetesl
      By fopetesl
      I need to be able to issue a command line which has a folder in parentheses as
       
      attrib +s +h "absolute folder to hide"  I've read through many posts here but nothing quite hacks how to use a variable as the folder in parentheses.
      I've tried
       
      Local $dosattrib = "attrib +s +h " & ""$hidFolder"" ; $hidFolder built up from decrypted encrypted C:\Hidden Folder which I do not want visible when compiled version is reverse engineered  which errors with excess parentheses but in single "" it doesn't work.
      There seems to be a relatively complicated method to make it work but surely there's a simple way?
       
       
    • TheDcoder
      By TheDcoder
      Hello Everyone , Are you tired of searching the forum for getting both the exit code & the stdout output? Then you are in the right place!

      With this UDF you can get the both output & exit code of the command or the console app! Or you can get the exit code of another process without having to use RunWait...
      Features:
      1. Simple & Lightweight (15 KB)
      2. Detailed comments & description
      3. Flexible functions with many optional parameters
      A BIG THANKS TO PsaltyDS for the functions! 2 of the (main) functions in the UDF are his work
       
      List of functions:
      Downloads:
      Grab the latest (in development) code from GitHub
       
      Hope it may help you, TD
       
      P.S Icon made by Freepik from www.flaticon.com, Modified by TheDcoder
    • Baboo85
      By Baboo85
      Hi all,
      I need to start a script that include:
      - admin privileges
      - multiple cmd commands
      - no bat, no exe, no tmp files created anywhere (especially in the user temp folder)
      In a bat file it would be simple, but users shouldn't see what commands I'm sending.
      Example of the script:
      echo off cls echo. echo I AM A TOOL echo. echo NOTE: echo - note 1 echo - note 2 echo - etc set USER1=0 set COMPUTER1=0 if /i %username% equ user.user ( set USER1=1 set COMPUTER1=1 ) if /i %username% equ another.user set USER1=1 if /i %computername% equ notebook set COMPUTER1=1 if %USER1% EQU 1 ( if %COMPUTER1% EQU 1 ( reg delete "HKLM\SOFTWARE\blablabla" /f ) else ( echo Computer not authorized. Contact assistance.) ) else ( echo User not authorized. Contact assistance.) echo. pause exit With the send("") is a disaster.
      I'm a noob here, so what can I do?
       
      EDIT: OR ELSE I explain the situation and what I need, so if there is a simple solution I can use that.
       
      SITUATION: our domain users have Users rights on the machine. Some of them need administrator rights.
      We create a local user with administrator rights, so that the users must insert username and password when asked to run something with administrator rights.
      We have an internal domain group policy that blocks EXE, BAT, COM, TMP files from the user local temp directory, for a security reason (malware). That also blocks most software installation.
      But some users are often out of office, away from workplace and in another country, they need a complete control on their computers.
       
      WHAT I NEED: I need to check the username and the computer name. If the username is the one with local administrator rights and the computer name is a computer that is qualified to temporary remove the policy, then I need to execute a REG DELETE command with administrator rights.
       
      I hope I explained myself.
       
      Thank you very much.
    • Eddi96
      By Eddi96
      Hey guys!
      I need your help again. So I am working on a Project with which I can Logoff a User in a Terminal-Server (Windows Server 2012 R2), logged in as Admin. Then backup the users partition and log him back in. Sounds pretty easy for you guys, right? So my problem is... I seem to not be able to get the User ID. You can see and display the ID in a textfile with:
      Run("query user>>c:\users\example\desktop\helpmeguys.txt") This line just writes a textfile of "query user" on the desktop. This is an example on what it looks like:
       BENUTZERNAME          SITZUNGSNAME       ID  STATUS  LEERLAUF   ANMELDEZEIT
      >wg                                  console                       2  Aktiv                     17    25.07.2016 08:19

      What I need right now is the ID. Any Idea on how to read it off of the Textfile?
      Please give me examples because I am still a rookie!
       
      With kind regards
      Eddi96
       
       
    • milky
      By milky
      Hello,
      I wrote a small AutoIt App which takes DOS formatted textfiles and forwards them to MS Word. I searched a lot for a programm which does this, but I didn't find one.
      The reason for it is an old DOS program, which is used a lot, even today. The user wanted to print the output of that programm with some other font-size, font-style and so on... We used WinPrint, but this is a printing only app, so no formatting can be done afterwards...
      The solution was, to print with the DOS prgramm to an file, e.g. C:\12345\output.txt ... then read this file, convert it to unicode, put this into word with some pre-defined font / page size and so on ... and then the user can re-format or print it now.
      Here is the main function of the Dos2Word programm I wrote:
      Func Convert2Word() ; keine datei da... If Not FileExists($sFilePath) Then Return ; noch in Beaarbeitung... If _WinAPI_FileInUse($sFilePath) Then Return ; nun aber... Local $sFilePathTemp = $sFilePath & "_" & _WinAPI_CreateGUID() & ".txt" FileMove($sFilePath, $sFilePathTemp, $FC_OVERWRITE) ; open word and create new document Local $oWord = _Word_Create() If @error Then ErrorExit("Fehler bei _Word_Create()") Local $oDoc = _Word_DocAdd($oWord) If @error Then ErrorExit("Fehler bei _Word_DocAdd()") ; seite definieren With $oDoc.PageSetup .PageHeight = $sPageHeight .PageWidth = $sPageWidth .TopMargin = $sTopMargin .BottomMargin = $sBottomMargin .LeftMargin = $sLeftMargin .RightMargin = $sRightMargin EndWith ; schrift und absatz With $oDoc.Range .Font.Name = $sFontName .Font.Size = $sFontSize EndWith With $oDoc.Range.ParagraphFormat .SpaceBefore = 0 .SpaceAfter = 0 .LineUnitBefore = 0 .LineUnitAfter = 0 .LineSpacingRule = 0 EndWith Local $hFile = FileOpen($sFilePathTemp, BitOR($FO_READ, $FO_BINARY)) Local $iError Local $iLine = 1 Do Local $sLine = FileReadLine($hFile, $iLine) $iError = @error $iLine += 1 ; ignore special escape line of cm.exe If StringLeft($sLine, 2) = Chr(27) & Chr(64) Then $sLine = StringTrimLeft($sLine, 2) $oDoc.Range.insertAfter(_WinAPI_MultiByteToWideChar($sLine, $sCodePage, 0, True) & @CRLF) Until $iError <> 0 ; und am ende löschen, sofern gewünscht FileClose($hFile) If $sFilesDelete <> "0" Then FileDelete($sFilePathTemp) EndFunc ;==>Convert2Word The Homepage of the program is here: https://mcmilk.de/projects/Dos2Word/

      The full source code and precompild signed binaries for 32bit and 64bit systems are also there, the License is GPLv2
      With best regards, Milky
      Maybe someone finds it useful too