Win: "launch [doc] with [app]" fails, & workaround

If you find an issue in LiveCode but are having difficulty pinning down a reliable recipe or want to sanity-check your findings with others, this is the place.

Please have one thread per issue, and try to summarize the issue concisely in the thread title so others can find related issues here.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
AxWald
Posts: 524
Joined: Thu Mar 06, 2014 2:57 pm

Win: "launch [doc] with [app]" fails, & workaround

Post by AxWald » Sat Apr 17, 2021 2:35 pm

Hi,

I'd like to have this confirmed before I write another bug report (or is there one already? not found)
This seems to be a very old bug, I see it in Win versions from 6.7.10 to the freshest RCs.
I've a sample stack attached, feel free to try yourselves - I hope it's not limited to my machines :)

When, in Windows, you call:

Code: Select all

   launch "D:/myDir/myFile.txt" with "D:/myDir/myApp.exe"
you'll see nothing happen. No myApp started, no myFile opened.
But you just have created a zombie process "myApp.exe".
If you'll repeat it, the same will happen.

"the result" will be empty or a (random?) number; when repeated, this again or sometimes "process is already open".
Find & kill the process in taskmanager, tab -2 (details).

This is evil, because it's the only way LC provides to open a document with a certain (not default) program. For instance, you may have Adobe suite installed, but you want a small, quick PDF viewer (SumatraPDF etc.) to safely display PDFs.
We could call:

Code: Select all

   get shell("D:/myDir/myApp.exe" "D:/myDir/myFile.txt")
This gives the expected result, but it will "freeze" LC until you close myApp again. Not really useful.

The workaround - we define a custom command:

Code: Select all

on LaunchWith theDocPath, theAppPath
   /* - Does what "launch [docPath] with [appPath]" is supposed to do -
   (both theDocPath & theAppPath are expected to be full paths (as from "ask file ...")
   
   Set up variables & defaultFolder:   */
   put the defaultFolder into myOldDF
   set itemdel to slash
   put item 1 to -2 of theAppPath into myAppPath
   put item -1 of theAppPath into myAppName
   if char 1 of myAppname = slash then delete char 1 of myAppName  --  WTF???
   set itemdel to comma
   set the defaultFolder to myAppPath
   
   /* Here's the beef:   */
   set the hideConsoleWindows to true
   get shell("start" && myAppName && quote & theDocPath & quote)
   set the defaultfolder to myOldDF
   if it is empty then
      /* The following line is for demonstration & may be commented:   */
      answer information "Done. You see, I responded before you closed the app!" titled "Info:"  
      
      exit LaunchWith
   end if
   /* In case something went wrong ...   */
   answer error "This shell call didn't work:" & CR & \
         "start" && myAppName && quote & theDocPath & quote & CR & \
         "in dir: " & myAppPath & CR & \
         "Result: " & it titled "Error:"
end LaunchWith
And then call simply:

Code: Select all

   Launchwith "D:/myDir/myFile.txt","D:/myDir/myApp.exe"
It's a bit convoluted, but it works.

Bonus bug: If the itemDel = slash, item -1 of a list may start with it ;-)

Have fun!

Edit: changed "function" to the correct "command" in the "Workaround" subtitle ...
Attachments
LaunchTest.zip
DemoStack for "Launch with", LC 5.5+
(5.89 KiB) Downloaded 31 times
Last edited by AxWald on Sat Apr 17, 2021 8:27 pm, edited 1 time in total.
Livecode programming until the cat hits the fan ...

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 868
Joined: Wed Nov 22, 2006 3:42 pm
Location: France
Contact:

Re: Win: "launch [doc] with [app]" fails, & workaround

Post by Thierry » Sat Apr 17, 2021 3:22 pm

AxWald wrote:
Sat Apr 17, 2021 2:35 pm
get shell("D:/myDir/myApp.exe" "D:/myDir/myFile.txt")
Hi Axwald,

Ok, first I think you have to pass only 1 string to the shell() function.

Second, I believe the command you are looking for new Win box is: start /b aCommand
which should be the equivalent of aCommand& in Mac/Unix.

Could be something like (pseudo code):

get shell( "start /b 'D:/myDir/myApp.exe' 'D:/myDir/myFile.txt'" )

If this doesn't work you could try changing the single quotes with double ones.

Sorry, no Win10 machine opened near me to test.
Might be worth a try...

Regards,

Thierry
Thierry Douez
- Senior computer scientist
- Conseil, dévelopement et support en Français
https://sunny-tdz.com
https://sunny-tdz.com/livecode/externals

AxWald
Posts: 524
Joined: Thu Mar 06, 2014 2:57 pm

Re: Win: "launch [doc] with [app]" fails, & workaround

Post by AxWald » Sat Apr 17, 2021 8:24 pm

Hi,
Thierry wrote:
Sat Apr 17, 2021 3:22 pm
Ok, first I think you have to pass only 1 string to the shell() function.
get shell("D:/myDir/myApp.exe" "D:/myDir/myFile.txt") works fine. But you can write:
get shell("D:/myDir/myApp.exe D:/myDir/myFile.txt"), too. Works as well :)
Thierry wrote:
Sat Apr 17, 2021 3:22 pm
Second, I believe the command you are looking for new Win box is: start /b aCommand
which should be the equivalent of aCommand& in Mac/Unix.
Actually, what does the job in the "LaunchWith" workaround is:
get shell("start" && myAppName && quote & theDocPath & quote) ;-)

"start" in Win is a beast - the only way I found to have it work as desired is to set the defaultFolder to the app's directiory, and use the app name w/o path: get shell("start myApp.exe" "D:/myDir/myFile.txt").

The "/b" parameter doesn't exist in Win, "/B" reads: "Starts app w/o opening a new window. The app ignores Strg-C ..." Sounds dangerous.

Have fun!
Livecode programming until the cat hits the fan ...

Post Reply

Return to “Bug Triage”