Page 1 of 1

Trouble with Shell Command

Posted: Tue Oct 20, 2015 11:21 pm
by buchacho
I am trying to get some text output from a shell command. My script is something like this:

Code: Select all


put "C:/PROGRA~2/PICO~1/PICOS~1/Ps.com /a M.CSV?" into tCommand
put shell (tCommand) 
When I run the script, the shell window opens, but there is no output (just a blinking cursor). I have to close the window in order for the LiveCode script to be able to terminate. If I run the command in the shell directly, it works fine and outputs a couple lines of text. I was wondering if the slash in the "/a" part is the issue, so I put the command in a batch file and ran that, but I got the same result. I tried adding an extra forward slash (//a), but the script ended up launching the Ps.com GUI. I am running Windows 7 and wondering if there is some kind of permissions issue. I ran LiveCode as an administrator, but it still does not work. Any ideas?

Re: Trouble with Shell Command

Posted: Tue Oct 20, 2015 11:30 pm
by SparkOut
I can't play with tests at the moment, but try wrapping the whole command line in another set of quotes, so that the arguments are passed as part of the shell command, as in
get shell(quote & tCommand & quote)
put it

Re: Trouble with Shell Command

Posted: Tue Oct 20, 2015 11:37 pm
by buchacho
SparkOut wrote:get shell(quote & tCommand & quote)
put it
Thanks for the suggestion. If I do this, the response I get is "The system cannot find the path specified.".

Re: Trouble with Shell Command

Posted: Wed Oct 21, 2015 12:33 am
by FourthWorld
Is that second argument a file path? If so it may need quotes around it.

Also, you can hide console windows by setting the hideConsoleWindows global property to true before calling the shell function.

Re: Trouble with Shell Command

Posted: Wed Oct 21, 2015 12:40 am
by buchacho
FourthWorld wrote:Is that second argument a file path? If so it may need quotes around it.
I believe it is a command. If I try "C:/PROGRA~2/PICO~1/PICOS~1/Ps.com /a ?" I get the same non-result. With that command, it should output a list of commands.
FourthWorld wrote:Also, you can hide console windows by setting the hideConsoleWindows global property to true before calling the shell function.
If I do that, I cannot close the window and then have to open the windows Task Manager to kill the process.

Re: Trouble with Shell Command

Posted: Fri Oct 23, 2015 12:11 am
by buchacho
Is there any way I can monitor what is happening? I am stuck here.

Re: Trouble with Shell Command

Posted: Wed Oct 28, 2015 8:46 pm
by buchacho
Any way I can troubleshoot what is going on with the cmd shell? As far as I can tell at the moment, there is a bug with the shell command.

Re: Trouble with Shell Command

Posted: Wed Oct 28, 2015 9:24 pm
by FourthWorld
What is the string returned from the function?
Does the command work in Window's shell?

Re: Trouble with Shell Command

Posted: Wed Oct 28, 2015 10:32 pm
by buchacho
FourthWorld wrote:What is the string returned from the function?
Unfortunately no string is returned when I attempt to run the test.bat file with the LiveCode shell command. There is just a blinking cursor, like it is waiting for something to happen.
FourthWorld wrote:Does the command work in Window's shell?
Yes, the output from the test.bat file looks something like this:

Code: Select all

2015-10-28, 02:12 PM 
0ms: Measurements.CSV?
A,AC RMS,565.7 mV,565.7 mV,565.7 mV,565.7 mV,94.19 æV,16,WholeTrace,
A,Maximum,800.2 mV,800.2 mV,800.3 mV,800.3 mV,103.9 æV,16,WholeTrace,

Re: Trouble with Shell Command

Posted: Wed Oct 28, 2015 10:39 pm
by buchacho
I also tried a .bat to .exe converter to create a test.exe to call from LiveCode. It works when I double-click the .exe in the Windows GUI, however, shell or launch LiveCode commands do not work with the "test.exe" either. For some reason the way LiveCode makes the shell or launch call is not allowing the underlying command to execute.

Re: Trouble with Shell Command

Posted: Wed Oct 28, 2015 11:25 pm
by FourthWorld
It might be a bug in LC, or it might be something specific to that program.

You might consider filing a bug report at http://quality.runrev.com/

You can also try "open process "<command>" for neither", whether "neither" means not waiting for reads or writes.

Re: Trouble with Shell Command

Posted: Tue Dec 08, 2020 2:47 am
by 5imon
I just ran into the same problem as buchacho and spent the better part of a few hours debugging it. I finally got it to work when formatted as the following:

Code: Select all

put "cd C:/Users/5imon/AppData/Local/HaptUX/ExManCmdWin/" into thePath
put "& ExManCmd /list" into theArgs
get shell(thePath & theArgs)
That works 100%.

However, if theArgs has multiple args then a peculiar quirk happens ...

Code: Select all

put "cd C:/Users/5imon/AppData/Local/HaptUX/ExManCmdWin/" into thePath
put "& ExManCmd /list all" into theArgs
get shell(thePath & theArgs)
... the Command Prompt app launches and makes itself visible for a few seconds (all the while with a blinking prompt), then disappears and Livecode completes get shell() as expected.

I'm only replying to this post with a solution because I want to also ask why the command prompt is being launched (I'll do that in a separate subject to avoid high jacking this one).

If you can live with seeing the command prompt launch for a split second then the above should work for you.