dxl CreateProcess failed for system cmd instruction - ibm-doors

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?

Related

Linux expect newline

I have a custom package I want to install automatically in my docker using expect.
The first thing the package asks me to do is press Enter to continue, then it prints another 2 empty lines then it waits for an input.
My expect script :
#!/usr/bin/expect -f
set timeout -1
spawn ./install
expect "\n"
send -- "\n"
But as you can see in the image, it just runs the installer and exits.
I tried removing the expect "\n" so only send -- "\n" will execute but now even the install message doesn't appear (tried with set timeout 1000 before send and it also didn't work)
Any ideas?
P.S : This is a link to the package if anyone wants to have a go at it:
https://www.bayometric.com/downloads/digital-persona/DP_UareU_Linux223_20140429.2.zip
(the installer is inside DP-UareU-RTE-2.2.3-1.20140429_1533.tar.gz)
expect "\n" match a linefeed exactly, I think this is not what your program is sending.
To wait for a Shell prompt you can use expect "%" or expect "*" to match anything.
If you need to make sure you're dealing with the right prompt you may be able to use something like expect "*Linux Installation*".
Also don't send \n but \r for the enter key :
#!/usr/bin/expect
spawn ./install
expect "*Linux Installation*"
send "\r"
expect eof
Note that the default flag is -gl for glob pattern matching but you can also use the -re flag for regular expression matching.

PigLatin and print a message

I'm using a grunt shell of PIGLATIN and I am trying to print a simple message, like in shell ECHO "result is :" and then result given by Pig script .
However I have done all the searches and no luck so far.
Echo returns error , same as print.
I can't use UDFs...
You can DUMP the alias or STORE the alias in to file to see the alias values.
Refer :
http://chimera.labs.oreilly.com/books/1234000001811/ch05.html#pl_dump
http://chimera.labs.oreilly.com/books/1234000001811/ch05.html#pl_store

XOJO how to pass arguments to external executable

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

What are error -10004 and error -10000 in Applescript

I have an Applescript that is working on my computer, but not on my colleague's. I get two errors when manipulating paths: -10004 and -10000. I have an idea on how to solve this, but first I'd like to understand those error codes.
Here is the script (I removed useless part, the full version is on github):
-- export all layers to image files
-- Settings
property exportFileExtension : "png"
property ADD_CANVAS_NUMBER : true
-- End of Settings
on file_exists(FileOrFolderToCheckString)
try
alias FileOrFolderToCheckString
return true
on error
return false
end try
end file_exists
tell application "OmniGraffle Professional 5"
set theWindow to front window
set theDocument to document of theWindow
set theFilename to name of theDocument
-- remove .graffle
-- FIRST ERROR IS HERE -10004
set theFilename to text 1 thru ((offset of "." in theFilename) - 1) of theFilename
set export_folder to (choose folder with prompt "Pick the destination folder") as string
set export_folder to export_folder & theFilename & ":"
-- create folder
if file_exists(export_folder) of me then
try
display alert "The file already exists. Do you want to replace it?" buttons {"Cancel", "Erase"} cancel button 1
on error errText number errNum
if (errNum is equal to -128) then
return
end if
end try
-- deletes the folder (necessary because some layers may have been renamed
do shell script "rm -rf " & quoted form of POSIX path of export_folder
else
-- creates the folder
do shell script "mkdir -p " & quoted form of POSIX path of export_folder
end if
set canvasCount to count of canvases of theDocument
set i to 0
repeat with canvasNumber from 1 to canvasCount
set theCanvas to canvas canvasNumber of theDocument
set canvas_name to name of theCanvas
set canvas of theWindow to theCanvas
set layerCount to count of layers of theCanvas
-- ...
set area type of current export settings to current canvas
set draws background of current export settings to false
set include border of current export settings to false
set canvas_filename to ""
-- ...
set canvas_filename to canvas_filename & canvas_name
repeat with layerNumber from 1 to layerCount
set theLayer to layer layerNumber of theCanvas
if (theLayer is prints) and (class of theLayer is not shared layer) then
set layer_name to name of theLayer as string
set filename to canvas_filename & " - " & layer_name & "." & exportFileExtension
set export_filename to export_folder & filename
-- show the layer, export, then hide the layer
if character 1 of layer_name is not "*" then
set visible of theLayer to true
-- SECOND ERROR IS HERE -1000
save theDocument in export_filename
set visible of theLayer to false
end if
end if
end repeat
end repeat
end tell
Here is the log:
tell application "OmniGraffle Professional 5"
get window 1
--> window id 5032
get document of window id 5032
--> document "MSD.graffle"
get name of document "MSD.graffle"
--> "MSD.graffle"
offset of "." in "MSD.graffle"
--> error number -10004
end tell
tell current application
offset of "." in "MSD.graffle"
--> 4
end tell
tell application "OmniGraffle Professional 5"
choose folder with prompt "Pick the destination folder"
--> alias "Macintosh HD:Users:Romain:Desktop:Temp:"
display alert "The file already exists. Do you want to replace it?" buttons {"Cancel", "Erase"} cancel button 1
--> {button returned:"Erase"}
do shell script "rm -rf '/Users/Romain/Desktop/Temp/MSD/'"
--> error number -10004
end tell
tell current application
do shell script "rm -rf '/Users/Romain/Desktop/Temp/MSD/'"
--> ""
end tell
tell application "OmniGraffle Professional 5"
...
...
save document "MSD.graffle" in "Macintosh HD:Users:Romain:Desktop:Temp:MSD:1- Navigation - 1Layout.png"
--> error number -10000
Result:
error "OmniGraffle Professional 5 got an error: AppleEvent handler failed." number -10000
Thanks!
I updated the script but I still get error -10000. Here are the modified lines:
save theDocument in file exportFilename
and
-- Create folder if does not exist, remove it otherwise
-- Shell script should not be executed inside tell application block
if file_exists(export_folder) of me then
try
display alert "The file already exists. Do you want to replace it?" buttons {"Cancel", "Erase"} cancel button 1
on error errText number errNum
if (errNum is equal to -128) then
return
end if
end try
tell me
-- Delete the folder
do shell script "rm -rf " & quoted form of POSIX path of export_folder
end tell
else
tell me
-- Create the folder
do shell script "mkdir -p " & quoted form of POSIX path of export_folder
end tell
end if
Errors -10000 - -10015 are event registry errors.
Error -10000 is not a target error per se, because it will throw an -1708 in those cases mostly. most of the time it is not a target error but an incomplete command or wrong usage of brackets. What if you use:
save theDocument in file export_filename
Error -10004 is a privilege violation error, which mean you're doing something with the file that isn't allowed. Probably you're not allowed to remove the file and do shell script command should always be used outside tell application blocks. The problem is that the target application can run as another user than the script. I'm not saying it is the error but there is a chance that it this is the problem. Otherwise you simply heve not enough privileges and you need to ask the user for administrator privileges.
do shell script "do something" with administrator privileges.
I haven't found where those error codes are documented, but they mainly deal with events that the targeted application isn't able to do. The first two errors -10004 are from using a Standard Additions command inside an application tell statement (offset and do shell script) - the application doesn't know what those commands are, passes the error up the chain to AppleScript, but AppleScript knows what they are and does it.
I don't have OmniGraffle, but the last error is telling you that the save command couldn't be performed, probably due to a problem with the destination not being a file specifier - it is just a text string, so you will probably have to coerce it into something that the command wants.

Does popen() add a line feed (\n) at the end of the result?

I've wrote a small function that returns the result of executing a command.
function axsh(cmd)
local fullCmd=cmd:lower()
local f,err=io.popen(fullCmd,"r")
if not f then
return nil,"Could not create the process '"..fullCmd.."' \nError:"..err
end
return f:read("*all")
end
s=axsh("echo hi")
--print all bytes
print(s:byte(1,s:len()))
The output always has a \n at the end no matter what is the command:
104 105 10
Edit: it happens not only for my own binary command line application but also for almost all OS commands: Windows: "dir", "ipconfig", "echo"... Linux: "ls", "pwd", "ls"...
But when I run the command separately (i.e. windows command prompt) there is no trailing line feed. I don't need it, so need to remove the last character before returning the result.
Question: does this line feed always exist in the result of popen()? I can't find any reference to this behavior in the documentation.
No. io.popen just returns whatever string the command produces. You use echo as command, which happens to put a newline after the string ( this is what makes the command prompt appear on the next line, instead of just after the output).
You can test it by using trying this:
s=axsh([[lua -e "io.write([=[hi]=])"]])
return string.byte(s,1,-1)
which does not end the output with a newline.

Resources