Jump to content

$CmdLineRaw not getting populated/empty?


Go to solution Solved by Tekk,

Recommended Posts

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:

2e5mlxz.jpg

Edited by EamonB
Link to comment
Share on other sites

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.  

Link to comment
Share on other sites

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:

2e5mlxz.jpg

Edited by EamonB
Link to comment
Share on other sites

  • Solution

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 by Tekk
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...