saywell Posted June 1, 2012 Share Posted June 1, 2012 After abandoning my quest to read text directly form a word rtf file, [thread passim] I'm trying to use a program called antiword which works from the command line and reads text from word documents.I'm having some problems automating it - or rather, with making it work on a file chosen via a shortcut.If I run this code#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_outfile=Antiword_Verify.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #Include <File.au3> #include <array.au3> #Include <File.au3> #Include <String.au3> Global $acontent FileDelete (@ScriptDir&"\test_text.txt") FileDelete (@ScriptDir&"\run.bat") _FileCreate (@ScriptDir&"\run.bat") $VerShortcut = FileOpenDialog("OPEN","S:\ClinicalDocuments\TestDirectorate_CDM\Saywell_William\My_Clin_Docs","Shortcuts (*.lnk)") $afile = FileGetShortcut($VerShortcut) ;_ArrayDisplay ($afile) $file = $afile[0] ClipPut ($file) $afile = "" ;MsgBox (0, "$file",$file) $doscommand = @ScriptDir&"\antiword.exe -t "&$file&" > test_text.txt" MsgBox (0, "doscommand",$doscommand) _FileWriteToLine (@ScriptDir&"\run.bat",1,$doscommand,1) _FileWriteToLine (@ScriptDir&"\run.bat",2,"Pause",1) RunWait(@ScriptDir&"\run.bat") ExitIt doesn't workBut if I pick up on a separate script taking from the clipboard the filepath left by the first script, it works perfectly.#Include <File.au3> #include <array.au3> #Include <File.au3> #Include <String.au3> Global $acontent FileDelete (@ScriptDir&"\test_text.txt") FileDelete (@ScriptDir&"\run.bat") _FileCreate (@ScriptDir&"\run.bat") $file = ClipGet() $doscommand = @ScriptDir&"\antiword.exe -t "&$file&" > test_text.txt" MsgBox (0, "doscommand",$doscommand) _FileWriteToLine (@ScriptDir&"\run.bat",1,$doscommand,1) _FileWriteToLine (@ScriptDir&"\run.bat",2,"Pause",1) EnvSet ("HOME", @ScriptDir & "\antiword\antiword.exe %1 %2") ;EnvSet ("HOME","") RunWait(@ScriptDir&"\run.bat")When it works, the output file appears in less than a second, and I've tried it with 20 sec sleeps to make sure it has enough time to run, but I can't get it to run successfully if I pick the file via the shortcut. The first script works fine if you start with a manually-entered file path.It's probably some daft rookie mistake, but I'd be grateful if you could look over my script extracts.You'll need to use a word doc [pref rtf, as that's what I'm using] and make a shortcut to it [mine are created within autoit]And yes, i have tried running RunWait(@ComSpec & " /c " & $doscommand, "", @SW_SHOW) but that failed too, and i thought I'd use the more transparent batch file method at least until I've found where the problem is. In fact, the @Comspec method works fine in the second-stage script, too [but not the first]Regards,William Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now