XOJO how to pass arguments to external executable - xojo

I need to open external exe file, and in the same time to pass some arguments to it.
The documentation in Xojo Library suggest to use the Shell, but I have not seen the practical example how to do it.
Xojo Shell command Explanation:
Dim sh As New Shell
sh.Execute("Location to a file")
I have tried the following:
sh.Execute("Location to a file" + " " + myArgumentOne + " " + myArgumentTwo)
There is no error, just the *.exe is not being run.
If there is solution using FolderItem, I would gladly use it as well.

You may not need to use a shell. When you have the folderitem, use Launch to execute the program and pass parameters. For instance
dim f as folderitem = GetFolderItem("C:\myprogram.exe", Folderitem.PathTypeShell)
f.Launch("Parameter1, Parameter2")
See http://docs.xojo.com/index.php/FolderItem.Launch

sh.Execute F.ShellPath +"\program.exe " + parameters
F is a Folderitm pointing to the directory of the program and parameters is a string

Related

dxl CreateProcess failed for system cmd instruction

I want to call run a file called csvplot.vbs (from this site) to turn a .csv file I have written using dxl (has 5 columns, each with a heading and then just numerical data) into a graph (stored as .png).
I have run the following instruction directly through cmd with success:
#echo off
cscript //nologo C:\Users\Administrator\csvplot.vbs C:\PROGRA~1\IBM\Rational\DOORS\9.6\lib\dxl\addins\Verification\Statistics\statGenTest_Top_Level.csv C:\PROGRA~1\IBM\Rational\DOORS\9.6\lib\dxl\addins\Verification\Statistics\statGenTest_Top_Level.png 800 600 1 3 1 4 1 5
pause
This produces the desired .png file.
What I want, however, is to be able to execute this through DOORS, so that whenever the script that generates the raw data is run, it also produces a graph.
What I have is this as my test case:
string echostr = "#echo off"
string commands = "cscript //nologo C:\\Users\\Administrator\\csvplot.vbs C:\\PROGRA~1\\IBM\\Rational\\DOORS\\9.6\\lib\\dxl\\addins\\Verification\\Statistics\\statGenTest_Top_Level.csv C:\\PROGRA~1\\IBM\\Rational\\DOORS\\9.6\\lib\\dxl\\addins\\Verification\\Statistics\\statGenTest_Top_Level.png 800 600 1 3 1 4 1 5"
system("cmd /c start #echo off") // doesn't recognise echo command
system("cmd /c start " commands "")
I get an error:
"Windows cannot find '#echo'. Make sure you typed the name correctly,
and then try again."
I am at a loss on how to get the script to run though cmd from dxl, and I would appreciate any help. I've only had one previous foray into system() prompts through dxl, and it was only to open a .pdf. In the meantime I will keep trying to work this out. Please let me know if I can provide any further information.
Edit: Further Information
#echo: I removed the # to see how it operates, it brings up a blank
cmd window and performs no further action. In order to even run the things in the points below, I left the # off.
I deleted "/c start" from the second system() line: this opens one command line with the usual white text at the top, and a second over the top that is completely blank.
I changed the first line as follows, and commented out the second:
system("cmd /c start echo off" "\n" commands "")
--- this got a similar result to the second dot-point, but only with one cmd window, the black (no text one)
If I don't include the "\n" marker then I get a cmd window with text of "off" commands (where commands is the defined string above).
If I only have the system("cmd /c start " commands "") line, and not the echo line, then a cmd window briefly flashes and disappears and no further results demonstrating the success of the script appear.
So my issue is this: I know this script works when run directly through command line, the problem I have is that I cannot now run it through dxl.
I have developed a solid work-around that does exactly what I need.
The issue was that the input I had dxl writing was not going through command line correctly.
Knowing that the script ran from cmd correctly and, in turn, that the script executed from a batch file correctly, and that I could run the batch file from dxl, my solution was as follows:
Define the paths in dxl using the format C:\PROGRA~1\PATHNAME\
Using the Stream write() command to write the instructions directly
to a .bat file
Then using the system() command to run the .bat file
I have included some of my code, so that maybe it might help someone attempting to do the same thing. (I'll gladly take any advice on better programming conventions.)
// functions used: genFileName(), assume if a variable is not declared here, it was declared under my globals
// genFileName() returns a string of the file name, replacing any " " with "_" so cmd doesn't cry when I run it
string basename = genFileName()
string fcsv = basename ".csv"
string csvPath = "blahblahthefilepath" fcsv
if(fileExists_(csvPath)) isFile = true
Stream fOut = append(csvPath)
// === if file does not exist, create, give column names
if( !isFile){
fOut << "Date and Time,count1,count2,count3,count4" "\n"
}
else ack ("File name exists, append stats to file?" // may not be necessary
// === print to file ===
fOut << datetime "," ctot "," ctc "," cti "," ctnc "\n"
// ===== Create Batch file to run grapher ===
string columnsToPlot = "1 3 1 4 1 5" // ==> may develop this to allow user to choose
string graphDim = "800 600" // ==> px dim, may develop for user choice
string fbat = basename ".bat"
string batPath = "blahblahthefilepath"
Stream batOut = write(batPath fbat)
batOut << "#echo off" "\n"
batOut << "title Batch file to plot statistics for " fcsv "\n"
batOut << "cscript //nologo " batPath "csvplot.vbs " batPath fcsv " " batPath basename ".png " graphDim " " columnsToPlot ""
system("cmd /c start " batPath fbat "")
// some infoBox feedback DB to tell the user that the files were created
Good luck to anyone else who is attempting something similar, and I hope this is of use to someone.
Does running the dxl script without the # in front of the echo command work?

How to know the compilation mode in a genrule

I'm using bazel to build my android project. I need to access an environment variable DEBUG(self-defined) to determine what value of BuildConfig.DEBUG should be, but I can't find any description about this in Bazel's doc. Does Bazel support this? Or what can I do to reach my intent?
Thanks very much for any help!
PS: I'm using the genrule rule to generate my BuildConfig.java, but the value of BuildConfig.DEBUG should be determined by the environment variable DEBUG:
genrule(
name = "build-config-genrule",
outs = [ "BuildConfig.java" ],
cmd = "echo 'package com.qzone;" +
"public class BuildConfig {" +
"public static final boolean DEBUG = ???;" +
"}' > $(#)"
)
You can use the $(COMPILATION_MODE) Make Variable in the genrule.cmd:
COMPILATION_MODE: "fastbuild", "dbg", or "opt".
See Make Variable substitution.
EDIT: Important to mention that COMPILATION_MODE reflects the value of the -c / --compilation_mode flag, but there's no way in general to specify values on the command line that you could access in genrule.cmd.

Enclosing a python Path variable in quotes?

I need help fixing a Python script, but know ABSOLUTELY NOTHING about Python (though I am an experienced programmer so I get the jargon.)
I have this script that is trying to write output to a generated path, but when I run it, it gives me an error saying something about "E:\Program", and when I check, sure enough, it creates a folder named "Program" in the root of my E: drive. I'm CERTAIN it is trying to write to "E:\Program Files" but the space is terminating the command.
I did find where "path" is assigned:
path = tkm.path_archuncomp + bs.path + bs.name + '.ext'
How would I enclose that path in quotes that are assigned to the variable?
Inserting the quotes character appears to be the same as languages like C. Simply use "slash" notion:
path = \" + some_variable + \"
Unfortunately for me, repairing the script is more complicated than that, and doing so only created errors, so I can't confirm that was done properly. :(

How to capture console output from TDUMP.EXE?

TDUMP.exe is file dumping utility from Delphi RAD Studio. If I run
tdump.exe myapp.exe
It will return some information about the myapp.exe.
I want to capture the console output of tdump.exe to my VCL gui application. I have tried the RunDosInMemo in http://delphi.about.com/cs/adptips2001/a/bltip0201_2.htm. The output result isn't same as command line console output. It always return:
ERROR: Can not open output file myapp.exe.
And myapp.exe file will be overwritten.
Running other console command with RunDosInMemo works as expected but not Delphi tdump.exe.
Any ideas why redirect console output doesn't work with tdump?
I am using the following code to invoke RunDosInMemo:
RunDosInMemo('tdump.exe ' + ParamStr(0), Memo1);
ParamStr(0) returns the full name to your exe including path that may contain spaces that needs to be quoted. Try:
RunDosInMemo('tdump.exe "' + ParamStr(0) + '"', Memo1);
As evident from the error message 'tdump' gives, it is not trying to read the contents of the file name you pass to it, on the contrary, it takes the filename for output.
What 'tdump' actually expects is to read file contents from its 'stdin'. The code you linked in the question is not suitable. You need to create at least two pipes, write contents of the input file to the write end of 'tdump's standard input and read 'tdump's output through the read end of the output pipe.
But this is not required, you can tell 'tdump' to read the file that's passed with an argument, not from stdin. Issue a tdump -? at a console and see the help. You'll notice this option:
-ns Disable support for redirecting stdin
You just need to change your call to make your procedure work:
RunDosInMemo('tdump.exe -ns ' + ParamStr(0), Memo1);

How to use the function ` performTaskWithPathArgumentsTimeout` of the UIAutomation class?

I am automating some test cases for an iPhone app and I am using the UIAutomation class. I want to use the function performTaskWithPathArgumentsTimeout, which I believe runs some external script. But I cant use it. I have the following code:
#import "revision3.js"
#import "tuneup/tuneup.js"
test("script call", function(target, app){
var target = UIATarget.localTarget();
var host = target.host();
var result = host.performTaskWithPathArgumentsTimeout("fwasim/Desktop/registration.js, ["null"], 5);
UIALogger.logDebug("exitCode: " + result.exitCode);
UIALogger.logDebug("stdout: " + result.stdout);
UIALogger.logDebug("stderr: " + result.stderr);
});
The instrument console says:
Error: launch path not accessible.
I have searched on the internet but there seems to be very scarce resources on UIAutomation class and more specifically on the above function. Can anyone tell me what I am doing wrong?
The performTaskWithPathArgumentsTimeout() method on the host is for executing shell programs not JavaScript. That error message is telling you that it can't find an executable command at the path you gave.
Here's how you could execute a command with that method:
var result = host.performTaskWithPathArgumentsTimeout("/usr/bin/whoami", [], 5);
That executes the whoami command that lives in the /usr/bin directory. That command just prints out the logged in username which you can get at with result.stdout as you're already using.
I'm not quite sure what you're trying to do here, though. From the looks of the script you were trying to execute (fwasim/Desktop/registration.js), are you just trying to run some registration tests that are in a different file? If so, there's an easier way to do that. Just type this:
#import "fwasim/Desktop/registration.js"
That tries to import that JavaScript file as if it was relative to the directory of the script file that is running. You'd only need performTaskWithPathArgumentsTimeout() if you're trying to execute an external shell script or something like that. It's not for executing JavaScript inside UI Automation.

Resources