rootx

Help run()

7 posts in this topic

I need help to understand why the run function does not work, but if i use it directly inside cmd shell the command works. $where is the name of the jpg file

ShellExecute(@ComSpec ," /k C:\Users\root\Desktop\test\exiftool.exe -p $FileName "&'"'&$where&'"'&" > "&'"'&@ScriptDir&"\out.txt"&'"',@ScriptDir);<----- work


Run("C:\Users\root\Desktop\test\exiftool.exe -p $FileName "&$where&" > "&@ScriptDir&"\out.txt",@ScriptDir);<--- doesn't work

I would use the run command!

Thx

Share this post


Link to post
Share on other sites



What is the Return Value and the value of @error after calling Run?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

What gives this?

Run('C:\Users\root\Desktop\test\exiftool.exe -p $FileName "' & $where & '" > "&@ScriptDir&"\out.txt', @ScriptDir);

Your version has issues with whitespace(s) in $where and/or @Scriptdir.


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

Put something like this into your script to see what it is using?

Consolewrite("$where [" & $where &"] " & @CRLF )
Consolewrite("@scriptdir [" & $scriptdir &"] " & @CRLF )

Show the output?


Skysnake

Why is the snake in the sky?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

The run command doesn't look right to me, perhaps try :

Run("C:\Users\root\Desktop\test\exiftool.exe -p " & $FileName & $where & " > " & @ScriptDir & "\out.txt", @ScriptDir)

Edit: ohh, I see that is an internal variable, then please ignore my post .. 

Edited by Deye

Share this post


Link to post
Share on other sites

I read on the help... and now work... But why?

Global $_ExePath = @ScriptDir & "\exiftool.exe"
$where = "C:\Users\root\Desktop\test\1.jpg"
$pid = Run(@ComSpec & " /c " & $_ExePath & " -p $FileName "&$where&" > "&@ScriptDir&"\out.txt",@ScriptDir)
ConsoleWrite($_ExePath & " -p $FileName "&$where&" > "&@ScriptDir&"\out.txt"&@CRLF)

 

Share this post


Link to post
Share on other sites

Calling "@comspec " calls cmd.exe command prompt to run the command. That is only required to call internal cmd commands such as "dir". In your case you are using a redirection to a file,

"> "&@ScriptDir&"\out.txt

The ">" operator is processed by cmd.exe.

 

To Get AutoIt to handle the redirection will require the use of "StdoutRead" command.

 

The following is untested, but a combination of the example in the StdoutRead help file, and your example.

#include <AutoItConstants.au3>
$iPID=Run($_ExePath & " -p $FileName "&$where, $sFilePath, @SW_HIDE, $STDOUT_CHILD)
ProcessWaitClose($iPID)
Local $sOutput = StdoutRead($iPID)
ConsoleWrite("Output is: "&@CRLF&$sOutput&@CRLF)

If you require your results in a file, @comspec is the easiest. If you are looking to manipulate the result immediatly in your script, you want StdoutRead / StderrRead.

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

    • rkr
      By rkr
      Hi, I have a software which has a 'run file'-ie; when i double click on that file, the input file of the software is run by the software. I wish to double click/execute this run file using autoit. how do i achieve this. i opened the software and it shows the input file and run file in same folder, i will put my autoitscript file too in same location. how do i simulate double clicking the run file (using its file name, say - abc.run ). I entered the following lines to make software window active - it became active, dont know how to go forward
      Winactivate("program title")
      winwaitactivate("program title")
      controlclick("program title","abc.run",1000,"primary",2) ; 1000 is ctrl id
    • tremolux66
      By tremolux66
      Initial Problem
      I've written several scripts with the following sequence:
      Execute a program using Run w/stdout+stderr captured Typically processes all the files in one directory tree to populate a second tree Execute a second program (also with Run) to monitor the products of the first program and Display a progress bar (percentage of output files complete) Also monitor the first program's process and exit when it terminates The script then calls ProcessWaitClose (no timeout) on the first program's process and Checks the first program's results Kills the monitor program if it hasn't already exited on its own. Sometimes, ProcessWaitClose returns 1 with @error = 0 and @extended = 0xCCCCCCCC (actually, 0xFFFFFFFFCCCCCCCC), which seems ambiguous: the documentation says that @error = non-zero and @extended = 0xCC... means an invalid PID (unclear what the return value is), and 1 is returned for non-existent processes (but no mention of @extended). The 1/0/0xCC... result seems to occur when the first program exits very quickly (with or without an error). Since the exit value is not available, the script scans the program's output and tries to determine whether it ran successfully. This has gotten complicated and unreliable.
      Partial Fix
      I've now implemented a much simpler approach that works for most cases:
      Modify the monitor program so that it ignores the other program's process (the monitor always gets killed by the script anyway) Execute the monitor program first using Run, then execute the processing program with RunWait When RunWait returns, the child process exit value is available, so the script can ignore its output (which isn't available anyway) If the monitor program is still running, kill it. Remaining Issue
      However, there are still a couple of cases where it's necessary to get both the exit value from the processing program and its output. Since RunWait doesn't capture stdout and stderr for the parent script, it's looking like I'll have to call RunWait and redirect the 2 streams to a temp file and then scan it. Also, to do the redirect, I think I'll have to use @ComSpec to execute the processing program, which adds an undesired layer.
      Does anybody have a better (cleaner) way to handle these cases?
    • e45678mail
      By e45678mail
      Hi~
      I have some question about how to enable the test mode via "Run" or "shellexecute" of command,
      was to tried :
      -----
      Run("bcdedit.exe /-set testsinging on", "C:\Windows\System32")
      and
      shellexecute("bcdedit.exe /-set testsinging on", "C:\Windows\System32")
      -----
      since this command must to run through administrator competence,
      have any method can accomplish it?
       
       
    • BlazerV60
      By BlazerV60
      Hello all,
      I've written the code below which launches chrome in incognito mode and then proceeds to go to the autoit website.
      From my understanding, the Run() command is also supposed to output the PID number related to the application that got launched from the Run command.
      However when I run the below lines, it outputs a PID number that is different from the newly launched chrome browser's PID number, does anyone know why and possibly explain how I could retrieve the accurate PID number associated with the newly launched browser?
      Global $iPid = Run(@ComSpec & ' /c start chrome.exe https://www.autoitscript.com/forum/ -incognito' ,"", "") msgbox(0,"",$iPid) Thank you,
      Brian
    • nacerbaaziz
      By nacerbaaziz
      Hello
      How are you
      I have a question, please.
      I've created a window and i need
      when i run the script if it detect an other copy from the same script was runing
       the script close the first copy Automatically and run a new copy
      I want an example to understand it