EamonB Posted August 2, 2014 Posted August 2, 2014 (edited) I want to do a simple test in eclipse where I pass parameters from Java code into my AutoIt exe where I print out the $cmdLineRaw value in a message box. Attached in the code I have in Java and the AutoIt Script code. Yet, when I run the code in Eclipse, the corresponding empty message box appears. I know I am not populating the $CmdLine array and passing in the parameters to the executable correctly, but I am not sure what I have overlooked. Any help would be appreciated! Thank you! My Java code: public class test { public static void main(String[] args) throws I0Exception, InterruptedException { String[] cmd = {"test", "testl", "test2"}; Runtime.getRuntime().exec("C:/Users/Eamon/Desktop/test.exe", cmd); } } My AutoIt script code: #include <Word.au3> #include <MsgBoxConstants.au3> MsgBox($MB_SYSTEMMODAL, "Print", $CmdLineRaw, 10) Resulting message box: Edited August 19, 2014 by EamonB
guinness Posted August 2, 2014 Posted August 2, 2014 Are you sure your java code is correct? UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
computergroove Posted August 2, 2014 Posted August 2, 2014 It looks like you are trying to display an array. You cant do that in a msgBox. Try #include <Word.au3> #include <Array.au3> _ArrayDisplay($CmdLineRaw) Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html
somdcomputerguy Posted August 2, 2014 Posted August 2, 2014 It looks like you are trying to display an array. You can't do that in a MsgBox. You can, one way is to specify the specific elements of the array, like this:MsgBox(0, "Count is " & UBound($Array), $Array[1] & @CRLF & $Array[2]...)Or you can define a variable with array elements and display that variable with MsgBox. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
Tekk Posted August 2, 2014 Posted August 2, 2014 It looks like you are trying to display an array. You cant do that in a msgBox. Try #include <Word.au3> #include <Array.au3> _ArrayDisplay($CmdLineRaw) $CmdLineRaw is a string, not an array. public Process exec(String[] cmdarray, String[] envp) http://www.tutorialspoint.com/java/lang/runtime_exec_envp.htm I don't know anything about java but it looks to me like cmdarray[0] should be the path to your executable and cmdarray[1-n] should be your passed arguments.
EamonB Posted August 2, 2014 Author Posted August 2, 2014 (edited) Thank you guys for the reply but the parameters are still not being passed. I understand that you are supposed to pass the parameters to the AutoIt exe by calling the Runtime.getRuntime().exec(exeLocation, cmdArray) and then AutoIt exe will use the cmdArray that was passed as the $CmdLine array that I call in the script, yet I am still getting an issue I changed up the script code to explicitly print each value of the $CmdLine array, but only the first line gets called and the result is incorrectly "0". On top of that, the other two message box's don't even appear. Am I doing something wrong? My Java Code: public class test { public static void main(String[] args) throws I0Exception, InterruptedException { String[] cmd = {"test", "testl", "test2"}; Runtime.getRuntime().exec("C:/Users/Eamon/Desktop/test.exe", cmd); } } My Autoit Script code: #include <Word.au3> #include <MsgBoxConstants.au3> MsgBox(0, "First Argument", $CmdLine[0]) MsgBox(0, "First Argument", $CmdLine[1]) MsgBox(0, "First Argument", $CmdLine[2]) Resulting msg box: Edited August 19, 2014 by EamonB
Solution Tekk Posted August 2, 2014 Solution Posted August 2, 2014 (edited) Please try this. It works for me. package test; import java.io.IOException; public class test { public static void main(String[] args) throws IOException, InterruptedException { String[] cmd = new String[4]; cmd[0] = "C:/Users/"Your Username"/Desktop/test.exe"; cmd[1] = "test"; cmd[2] = "test1"; cmd[3] = "test2"; Runtime.getRuntime().exec(cmd, null); } } Edited August 2, 2014 by Tekk
EamonB Posted August 3, 2014 Author Posted August 3, 2014 Thank you Tekk! I tried that and it runs perfectly. I now know you are supposed to pass the location of the executable as the value of the first index of the cmdArray
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