rootx

Help run()

7 posts in this topic

#1 ·  Posted

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



#2 ·  Posted

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

#3 ·  Posted

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

#4 ·  Posted

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

#6 ·  Posted

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

#7 ·  Posted

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

    • 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
    • kawliga751
      By kawliga751
      I am attempting to run an Autoit.exe with schtasks every weekday @ 9:05 am.
      I have the below
      C:\>SchTasks /Create /TN "P10Run" /TR "O:\AUTOIT\P40 Run.au3" /SC WEEKLY /D MON, TUE,WED,THU,FRI /ST 09:05:00 SUCCESS: The scheduled task "P10Run" has successfully been created. I also did a "test" run :
      C:\>Schtasks /Run /TN "P10Run SUCCESS: Attempted to run the scheduled task "P10Run". But when I run my query to verify success my "Last Result" seems to indicate that the script did not run:
      C:\>SCHTASKS /QUERY /FO LIST /V /TN "P10RUN" Folder: \ HostName: xxxxxxxxxxxxxxxx TaskName: \P10RUN Next Run Time: N/A Status: Could not start Logon Mode: Interactive only Last Run Time: 6/14/2017 9:08:56 AM Last Result: -2147024894 Author: xxxxxxx Task To Run: O:\AUTOIT\P40 Run.au3 Start In: N/A Comment: N/A Scheduled Task State: Enabled Idle Time: Disabled Power Management: Stop On Battery Mode, No Start On Batterie s Run As User: xxxxxxxxx\xxxxxxxx Delete Task If Not Rescheduled: Enabled Stop Task If Runs X Hours and X Mins: 72:00:00 Schedule: Scheduling data is not available in this f ormat. Schedule Type: Weekly Start Time: 9:05:00 AM Start Date: 6/14/2017 End Date: N/A Days: MON, TUE, WED, THU, FRI Months: Every 1 week(s) Repeat: Every: Disabled Repeat: Until: Time: Disabled Repeat: Until: Duration: Disabled Repeat: Stop If Still Running: Disabled C:\> Is there something missing in my command? Also is there a better way to make sure that the script does in fact sun successfully?
      Thanks In Advance! 
    • AnonymousX
      By AnonymousX
      Hello,
      What command would I use to open the following folder directories for:
      Computer/This PC (windows 7/Windows 10)
      Libraries\documents
      Libraries\Pictures
      I know:
       Run("Explorer.exe " & $filepath) ShellExecute($filepath) can be used to open folder locations when you type in the full directory such as "C:\Users\%username%\Documents" but I'm trying to figure out how to use these windows short paths. 
      Thanks,
    • StMaSi
      By StMaSi
      I'm attempting to code a Run or RunWait command that is a little on the long side and contains multiple sets of embedded quotes (as it would be issued from a CMD prompt), but can't for the life of me figure out the containing quotes as pertains to AutoIt. Here's the one-line command as it would be issued via a CMD prompt...
      "\\AppServ\G$\Connectivity\Clients\Citrix\Receiver\14.5.0.10018\CitrixReceiver.exe" ADDLOCAL="ReceiverInside,ICA_Client,WebHelper,SSON,AM,SELFSERVICE,USB,DesktopViewer,Flash,Vd3d" ALLOWADDSTORE=A ALLOWSAVEPWD=A ENABLEPRELAUNCH=Y ENABLE_SSON=Yes STORE0="AppStore;https://receiver.domain.net/Citrix/Apps/discovery;on;AppStore" /EnableCEIP=false /includeSSON /noreboot /silent I've tried so many different combinations of surrounding quotes with Run and RunWait, I just don't understand why it's this difficult to get past this.
      Can anyone assist with this?
      Thank you.