Hey Guys, whats up... I am a beginner.
I've been playing around with LiveCode for 2 months now.
I am getting a bit annoyed with the errors that i sometimes get not because of the code but sometimes because of the LiveCode program itself. Sometimes i run into problems that basically causes me to dissect every little piece of text and bring it back to the most basic way just to see if LiveCode even excepts such executions. For some reason, which i have not gotten in depth for, yet, restarting LiveCode solves some errors. It may have to do with certain variables or parameters getting stuck in memory somewhere.
...I really dont know. I'm a beginner like i said.
Anyways, Ive been trying to figure this little issue out for a while, I feel like i've re-worked the code a million times with many different settings that i may be screwing stuff up and permanently setting some function variables which i have yet to figure out how to undo.
My small problem is this...
I am making a little transferring application. Using put url.
The information i am sending is first generated by a windows executable.
We all know that the drive letter on USB drives change all the time.
If I use windows commands to discover what my path is i can simply use 'cd', which will give me somethine like F:\folder\folder or
C:\somefolder\folder\programfolder\ ...from that ouput i know that my command/script is running from F or C.
When i try to run an executable in LiveCode, I am doing this,
set the shellCommand to "C:\Windows\System32\cmd.exe"
do Shell("Application.exe")
But i get error at line # (do: error in source expression) near "'Application.exe' is not recognized as an internal or external command", char 1
If i change that to "C:\Application.exe" - it will run
If i remove the set the shellCommand function or put empty into it,
i get a error that says error at line n/a (shell: cant run shell command) near " /C C:\Application.exe"
Why does LiveCode run commands with "/C" and how can i remove that - or - how can i discover in what drive my application is running from.
Help with Shell(Application.exe)
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Help with Shell(Application.exe)
Ok, a couple things.
First you shouldn't need to set the shell command.
Second, the purpose of "do" is a bit different than you think. With "do" you can execute code that is contained in a string, or you can execute scripts that are in a supported alternate language.
For example, you can have a variable tVariable that contains a string such as "answer the short name of this card".
Then if you
do tVariable it will execute "answer the short name of this card" and will pop up an answer dialog with the short name of the card displayed.
Or if you have vbscript (or javascript) in a variable you can
do myVariable as "vbscript" and it will use the system to execute the vbscript (though this can get complicated fast)
When you are dealing with functions (and shell is a function) you must do something with the output.
You can use "get'
get shell("mycommand.exe") <-- this will put the output of "mycommand.exe" into the special variable "it" if there was an error like command not found, that will be contained in "it"
You can also use "put"
put shell("mycommand.exe") into myContainer (this could be a field, a variable or anything that can contain the results of the command)
You can also use the results in different ways such as conditionals
if "mystring" is among the lines of shell("myCommand") then --
Or if a function does some processing and returns true or false this can also be used as a conditional..
if myfunction() then -- if the function returns true then..
-- do this stuff
else -- it returned false so
-- do something else
end if
Part of the reason you can make things work with a full path shell("c:\path\to\command.exe") is because you are telling shell EXACTLY where to find the file. If you just use shell("command.exe") it must be in the path (and a shell might have different path than a real command prompt) or the shell must start up in the correct location that contains the command. Its always safer to hard code locations.
I don't know if you have seen these resources, but there are a bunch of beginner tutorials on the runrev site at http://lessons.runrev.com and also at http://www.runrev.com/developers/lesson ... nferences/
These are really good places to start getting a handle on things.
First you shouldn't need to set the shell command.
Second, the purpose of "do" is a bit different than you think. With "do" you can execute code that is contained in a string, or you can execute scripts that are in a supported alternate language.
For example, you can have a variable tVariable that contains a string such as "answer the short name of this card".
Then if you
do tVariable it will execute "answer the short name of this card" and will pop up an answer dialog with the short name of the card displayed.
Or if you have vbscript (or javascript) in a variable you can
do myVariable as "vbscript" and it will use the system to execute the vbscript (though this can get complicated fast)
When you are dealing with functions (and shell is a function) you must do something with the output.
You can use "get'
get shell("mycommand.exe") <-- this will put the output of "mycommand.exe" into the special variable "it" if there was an error like command not found, that will be contained in "it"
You can also use "put"
put shell("mycommand.exe") into myContainer (this could be a field, a variable or anything that can contain the results of the command)
You can also use the results in different ways such as conditionals
if "mystring" is among the lines of shell("myCommand") then --
Or if a function does some processing and returns true or false this can also be used as a conditional..
if myfunction() then -- if the function returns true then..
-- do this stuff
else -- it returned false so
-- do something else
end if
Part of the reason you can make things work with a full path shell("c:\path\to\command.exe") is because you are telling shell EXACTLY where to find the file. If you just use shell("command.exe") it must be in the path (and a shell might have different path than a real command prompt) or the shell must start up in the correct location that contains the command. Its always safer to hard code locations.
I don't know if you have seen these resources, but there are a bunch of beginner tutorials on the runrev site at http://lessons.runrev.com and also at http://www.runrev.com/developers/lesson ... nferences/
These are really good places to start getting a handle on things.
-
- Posts: 5
- Joined: Mon Aug 06, 2012 3:12 am
Re: Help with Shell(Application.exe)
Thank you very much for your information. I did not know that you could do some of the things you explained.
Ultimately I ran into some code that was useful
the code being: put the effective filename of this stack into
This tells me where my code, whether in IDE mode or from standalone, is running from.
This is exactly what I wanted since I want to be able to run this program even when its in several levels of directories.
Hopefully it will not have problem in the future but i will test with uncommon directory paths to see if the code works well.
After i get the path of where it is running, i use: replace "/" with "\" varPathLong
to change it so that i can use Shell(path\path\path) instead of Shell(path/path/path) - since LiveCode did not accept the forward slash in the Shell function.
Thank you
Ultimately I ran into some code that was useful
the code being: put the effective filename of this stack into
This tells me where my code, whether in IDE mode or from standalone, is running from.
This is exactly what I wanted since I want to be able to run this program even when its in several levels of directories.
Hopefully it will not have problem in the future but i will test with uncommon directory paths to see if the code works well.
After i get the path of where it is running, i use: replace "/" with "\" varPathLong
to change it so that i can use Shell(path\path\path) instead of Shell(path/path/path) - since LiveCode did not accept the forward slash in the Shell function.
Thank you
Re: Help with Shell(Application.exe)
Hi,
1. wecome to the forum!
2. I recommend to check these stacks, great learning resources:
http://www.runrev.com/developers/lesson ... nferences/
Best
Klaus
1. wecome to the forum!

2. I recommend to check these stacks, great learning resources:
http://www.runrev.com/developers/lesson ... nferences/
Best
Klaus