Sign in to follow this  
Followers 0
trof

Strange script behavior

20 posts in this topic

Hi,   Greetings to all forum members
 
 
I don't know if I post in the correct forum section, sorry if I made a mistake
 
 
I have a strange behavior of myscript:
 
#RequireAdmin
Opt("ExpandEnvStrings", 1)
Opt("ExpandVarStrings", 1)

Local $bak = ClipGet()
Run(@ComSpec & " /c " & 'fnr --cl --find $bak$ --replace D:\ --dir %USERPROFILE%\sosttext --fileMask *.* --silent', "", @SW_HIDE)
(fnr is program to replace text strings)
When I run it from Scite editor or after I compiled it from windows prompt or double click, it works great,
but when I insert it in a batch file (that's what I need) I have the following error:
ERROR: The option --dir is mandatory, you must define it.
 
This is my batch file:
 
FOR %%n IN (D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF EXIST %%n:\partizionedati.txt SET DiscoD=%%n:
findstr .. %DiscoD%\dati.txt |clip
start %DiscoD%\myscript.exe
 
 

Share this post


Link to post
Share on other sites



here's how i'd go about it:

replace Run("Your Command Line") with MsgBox(0,"title","Your Command Line")

run it 1) in Scite, 2) compiled, and 3) from batch. this will give you indication if anything is different.

my guess would be %USERPROFILE% not being properly translated to absolute path.

Share this post


Link to post
Share on other sites

The script works well when I run it from Scite editor, windows prompt or double click, but it doesn't work when I lunch it from a batch file.

I replaced %USERPROFILE% with C:UsersVincenzo, but the problem is the same.

Is there an alternative syntax for  "fnr --cl --find $bak$ --replace D: --dir C:UsersVincenzososttext --fileMask *.* --silent"  ?

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

MsgBox tell me:

fnr --cl --find D:
 --replace T: --dir C:UsersVincenzososttext --fileMask *.* --silent
 
after "D:" ($bak$) it wraps. How to fix this?
Edited by trof

Share this post


Link to post
Share on other sites

the point is this: is the MsgBox output different when launched from batch file, compared to when launched by other method?

Share this post


Link to post
Share on other sites
Probably I understand that problem occurs when the clipboard is empty.
Probably findstr is not working in the batch file.
 

 

the point is this: is the MsgBox output different when launched from batch file, compared to when launched by other method?

 

When the clipboard is empty the MsgBox output is the same and is:

fnr --cl --find D:

 --replace T: --dir C:UsersVincenzososttext --fileMask *.* --silent

When the clipboard is full is different

 
I'd like to override findstr
Is there a way to send to clipbord the content of a text file?

Share this post


Link to post
Share on other sites

ClipPut()

there are more advanced functions also, see the help file.

Share this post


Link to post
Share on other sites

ClipPut() doesn't allow me to put content of a text file in the clipboard.

I'm a newbie, please give some suggestion.

Share this post


Link to post
Share on other sites

what's wrong with FileRead() to read the text file into a string, then ClipPut(), like this:

ClipPut(FileRead("textfile.txt"))

being a newbie is not enough justification to avoid thinking...

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Thanks,

ClipPut(FileRead("textfile.txt"))  work well,

but script doesn't work nor in SciTE editor

Edited by trof

Share this post


Link to post
Share on other sites

well, back to square #1 then. i did not understand from your description: at the first time, is there a difference between the output between the 3 modes of launch? can you post screenshots of that difference, indicate when it works and when not?

also, in the batch file, try remove the "start" command.

Share this post


Link to post
Share on other sites

Since I add to AutoIt script ClipPut(FileRead("textfile.txt")), it doesn't work at all.

I even removed "start" from my batch file.

I tried with fart, another replace strings program. MsgBox show the correct command line but the script doesn't replace strings at all

#RequireAdmin
Opt("ExpandEnvStrings", 1)
Opt("ExpandVarStrings", 1)

ClipPut(FileRead("D:\dati.txt"))
Local $bak = ClipGet()
Run(@ComSpec & " /c " & 'fart.exe -i %USERPROFILE%\sosttext\regD.reg $bak$ %DiscoD%\', "", @SW_HIDE)
MsgBox(0,"title","fart.exe -i %USERPROFILE%\sosttext\regD.reg $bak$ %DiscoD%\")

post-75864-0-79288800-1370258711_thumb.j

post-75864-0-34250900-1370258725_thumb.j

post-75864-0-52856600-1370258742_thumb.j

post-75864-0-17250800-1370259117_thumb.j

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

back to the original script, how about this: replace $bak$ with the following (the double-quotes may be unnecessary):

Run(@ComSpec & " /c " & 'fnr --cl --find "'&$bak&'" --replace D: --dir %USERPROFILE%sosttext --fileMask *.* --silent', "", @SW_HIDE)
Edited by orbs

Share this post


Link to post
Share on other sites

Why in the world are you copying the file to the clipboard just to read it back into another variable? Why not just read the file directly into the variable in the first place and avoid the clipboard all together?

Instead of:

ClipPut(FileRead("D:\dati.txt"))
Local $bak = ClipGet()
Use this:

Local $bak = FileRead("D:\dati.txt")

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

I think, its not a good idea to use an au3-script for batch-files.

The betterway: Do all, what you want, with au3 - not with batch. Its more effective than.


Best Regards BugFix  

Share this post


Link to post
Share on other sites
Here is a working script
 
#RequireAdmin
Opt("ExpandEnvStrings", 1)
Opt("ExpandVarStrings", 1)
Local $aSplit = StringSplit('D E F G H I J K L M N O P Q R S T U V W X Y Z', ' '), _
        $sDrive = '', _
        $sUserName = @UserName
For $i = 1 To $aSplit[0]
    If FileExists($aSplit[$i] & ':\partizionedati.txt') Then
        $sDrive = $aSplit[$i] & ':\'
        Local $bak = FileRead("$sDrive$dati.txt")
        Run(@ComSpec & " /c " & 'fnr --cl --replace $sDrive$ --dir %USERPROFILE%\sosttext --fileMask *.* --find $bak$"', "", @SW_HIDE)
        ExitLoop
    EndIf
Next
 
The hard part of this script is made by user guinness
 
 
this is also good
 
#RequireAdmin
Opt("ExpandEnvStrings", 1)
Opt("ExpandVarStrings", 1)
Local $aSplit = StringSplit('D E F G H I J K L M N O P Q R S T U V W X Y Z', ' '), _
        $sDrive = '', _
        $sUserName = @UserName
For $i = 1 To $aSplit[0]
    If FileExists($aSplit[$i] & ':\partizionedati.txt') Then
        $sDrive = $aSplit[$i] & ':\'
        #include <Process.au3>
        ClipPut(FileRead("$sDrive$dati.txt"))
        Local $bak = ClipGet()
        Local $rc = _RunDos("fnr --cl --replace $sDrive$ --dir %USERPROFILE%\sosttext --fileMask *.* --find $bak$")
        MsgBox(0,"title","fnr --cl --replace $sDrive$ --dir %USERPROFILE%\sosttext --fileMask *.* --find $bak$")
        ExitLoop
    EndIf
Next
 
this, very similar, but doesn't work
 
#RequireAdmin
Opt("ExpandEnvStrings", 1)
Opt("ExpandVarStrings", 1)
Local $aSplit = StringSplit('D E F G H I J K L M N O P Q R S T U V W X Y Z', ' '), _
        $sDrive = '', _
        $sUserName = @UserName
For $i = 1 To $aSplit[0]
    If FileExists($aSplit[$i] & ':\partizionedata.txt') Then
        $sDrive = $aSplit[$i] & ':\'
        ClipPut(FileRead("$sDrive$dati.txt"))
        Local $bak = ClipGet()
        Run(@ComSpec & " /c " & 'fnr --cl --replace $sDrive$ --dir %USERPROFILE%\sosttext --fileMask *.* --find $bak$"', "", @SW_HIDE)
        MsgBox(0,"title","fnr --cl --replace $sDrive$ --dir %USERPROFILE%\sosttext --fileMask *.* --find $bak$")
        ExitLoop
    EndIf
Next
 
 
The problem was that, in the previous scripts, Autoit wraps after expanding $bak$ variable. So I put $bak$ at the end of the line.
But there some mysteries:
 
1)
  this script
#RequireAdmin
Opt("ExpandEnvStrings", 1)
Opt("ExpandVarStrings", 1)

Local $bak = ClipGet()
Run(@ComSpec & " /c " & 'fnr --cl --find $bak$ --replace D:\ --dir %USERPROFILE%\sosttext --fileMask *.* --silent', "", @SW_HIDE)
  
  works good when lunched from SciTE editor but it doesn't work when I run it from a batch file
  
  
2)
  this script works in SciTE editor
  
#RequireAdmin
Opt("ExpandEnvStrings", 1)
Opt("ExpandVarStrings", 1)

Local $bak = ClipGet()
Run(@ComSpec & " /c " & 'fnr --cl --find $bak$ --replace T:\ --dir %USERPROFILE%\sosttext --fileMask *.* --silent', "", @SW_HIDE)
 
 
  this (very similar) doesn't work
#RequireAdmin
Opt("ExpandEnvStrings", 1)
Opt("ExpandVarStrings", 1)

ClipPut(FileRead("D:\dati.txt"))
Local $bak = ClipGet()
Run(@ComSpec & " /c " & 'fnr --cl --find $bak$ --replace T:\ --dir %USERPROFILE%\sosttext --fileMask *.* --silent', "", @SW_HIDE)
 
 
orbs thank you very much, 
if you can, please explain these strange behaviors?
thanks BrewManNH

Share this post


Link to post
Share on other sites

Try this with the Run line:

Run(@ComSpec & " /c " & 'fnr --cl --replace ' & $sDrive & ' --dir "'& @UserProfileDir & '\sosttext" --fileMask *.* --find ' &  $bak , "", @SW_HIDE)
This way you don't need to worry about the environment or autoit variable expansions, which you were doing wrong anyways.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Thanks.

If I change the order of the command line script doesn't work

Run(@ComSpec & " /c " & 'fnr --cl --find ' & $bak & ' --replace ' & $sDrive & ' --dir "'& @UserProfileDir & '\sosttext" --fileMask *.* ', "", @SW_HIDE)
I have the following error from fnr
ERROR: The option --dir is mandatory, you must define it.

Share this post


Link to post
Share on other sites

Then I guess the answer should be obvious to you shouldn't it?

Don't change the order of the command line?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Yes, I don't change the order of the command line

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
Sign in to follow this  
Followers 0