Normal Topic Passing @Asynchshell both application and data (Read 935 times)
Rick_R
Full Member
***
Offline



Posts: 243
Joined: Jan 29th, 2010
Passing @Asynchshell both application and data
Feb 20th, 2011 at 5:02am
Print Post Print Post  
I'm trying to open an HTML file in a browser using @Asynchshell and I keep getting an error message that Windows can't find it.  I want to pass both the (full) browser path and the full path of the HTML file, not rely on whatever the default browser and associated application are.  (I expect to use the same approach for non-browser programs.)

If I don't include the data file, either MSIE or FireFox opens, depending on which I specify.  But no combination of app plus data path works.  Individual users use different applications for the same data file type (e.g., sometimes open .doc in MS Word, sometimes in WordPerfect, etc.) Standardizing is not an option  Also, I really don't want to start putting batch files all over the place.

I'm using XP Home. The error message I get is: Windows cannot find '<the Cmdline string surrounded by single quotes>'.  Make sure you typed the name correctly, and then try again.  To search for a file, click the Start button, and then click Search.

Although I don't see any examples of full program+data paths in the programming manual, it gives the impression that it should be possible to pass both the full application path and full data file path to @Asynchshell and open the file.  Or does passing both require using @Shell plus Start?


stat sHTMLBrowser as String
stat sDefaultHelpPath as String      // Full path


Function ViewHTMLHelp(vHelpPath as String, vHelpDocName as String) as Int
     var n as Int
     var CmdLine as String
     
     If vHelpPath = "" then vHelpPath = sDefaultHelpPath
     If @Right(vHelpPath, 1) <> "\" then vHelpPath = vHelpPath + "\"

/* All 4 of the following fail. The difference is the various double quotes.
     CmdLine = @chr(34) + sHTMLBrowser + @chr(34) + " " + @chr(34) + vHelpPath + vHelpDocName + @chr(34)
=      "C:\Program Files\Internet Explorer\iexplore.exe" "G:\Sesame\Help\Index.html"
     (I use this syntax in various non-Sesame Windows shortcuts with no problem. If the resulting Cmdline line is copied
        from the Write() window and pasted into a command prompt, it works fine.)

     CmdLine = sHTMLBrowser + " " + @chr(34) + vHelpPath + vHelpDocName + @chr(34)
=      C:\Program Files\Internet Explorer\iexplore.exe "G:\Sesame\Help\Index.html"

     CmdLine = sHTMLBrowser + " " + vHelpPath + vHelpDocName
=      C:\Program Files\Internet Explorer\iexplore.exe G:\Sesame\Help\Index.html

     CmdLine = @chr(34) + sHTMLBrowser + " " + vHelpPath + vHelpDocName + @chr(34)
=      "C:\Program Files\Internet Explorer\iexplore.exe G:\Sesame\Help\Index.html"

*/

     CmdLine = sHTMLBrowser + " " + vHelpPath + vHelpDocName

     OpenSlate()
     Writeln(sHTMLBrowser)
     Writeln(vHelpPath)
     Writeln(vHelpDocName)
     Writeln(CmdLine)

//      n = @Asynchshell(sHTMLBrowser)  // This works with either browser but doesn't open the page, of course.
     n = @Asynchshell(CmdLine)  // This fails with either browser
     Return(n)
End Function


sHTMLBrowser = "C:\Program Files\Internet Explorer\iexplore.exe"
//      sHTMLBrowser = "C:\Program Files\Mozilla Firefox\firefox.exe"
sDefaultHelpPath = "G:\Sesame\Help\"
  
Back to top
 
IP Logged
 
Rick_R
Full Member
***
Offline



Posts: 243
Joined: Jan 29th, 2010
Re: Passing @Asynchshell both application and data
Reply #1 - Feb 20th, 2011 at 5:29am
Print Post Print Post  
I was able to get a browser to start and open a page by replacing @Asynchshell with @Shell and adding "Start " + to the first version of the Cmdline in the example.  However, (at least in Preview mode ...) it comes out pretty slow and ugly and doesn't open the specified browser.  A DOS C:\Windows\system32\cmd.exe window pops up with a hyphen blinking for a full 30 seconds while the page loads, giving the impression something has frozen.  The page is only 2 lines of text in extremely basic HTML. Everything is on the local drive. Even though I specify to open the page with MSIE, it is still opening in Firefox (my default browser) instead.

This is the Cmdline being passed to @Shell:

Start "C:\Program Files\Internet Explorer\iexplore.exe" "G:\Sesame\Help\Index.html"

  
Back to top
 
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Passing @Asynchshell both application and data
Reply #2 - Feb 21st, 2011 at 12:40am
Print Post Print Post  
First, you must drop the "Start" portion. This is causing your default browser to open the target file. Then, use one of the two examples below.

Code
Select All
var n as Int
var CmdLine as String

CmdLine = @Chr(34) + "C:\Program Files (x86)\Internet Explorer\iexplore.exe" + @Chr(34) + " " + @Chr(34)+ "S:\Sesame2\HelpFiles\index.html" + @Chr(34)

// Option 1
n = @Shell(@Chr(34) + CmdLine + @Chr(34)) // Works, but leaves a cmd window open.

// Option 2
CreateAProcess(CmdLine) // Works best. Does NOT leave a cmd window open. 

  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
Rick_R
Full Member
***
Offline



Posts: 243
Joined: Jan 29th, 2010
Re: Passing @Asynchshell both application and data
Reply #3 - Feb 21st, 2011 at 1:08am
Print Post Print Post  
Thanks.  Here is the problem--This is from the description for CreateAProcess, the description of @ASynchShell doesn't mention this:

@ASynchShell takes as its argument a file that is "opened", "executed", "printed", etc. based on the file association of its extension

[CreateAProcess] takes an actual command line. Like @Shell, this command can accept a full command line, including switches and arguments.

[CreateAProcess] takes one argument, the full command to run. It returns no values.
  
Back to top
 
IP Logged
 
Rick_R
Full Member
***
Offline



Posts: 243
Joined: Jan 29th, 2010
THREAD SUMMARY - NOT POSSIBLE
Reply #4 - Feb 21st, 2011 at 1:10am
Print Post Print Post  
A summary of this thread -- @ASynchShell() can't take both an executable name and a data file.  Use CreateAProcess().
« Last Edit: Feb 21st, 2011 at 9:46pm by Rick_R »  
Back to top
 
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Passing @Asynchshell both application and data
Reply #5 - Feb 21st, 2011 at 12:37pm
Print Post Print Post  
Rick_R wrote on Feb 21st, 2011 at 1:10am:
A summary of this thread -- @ASynchShell() can't take both an executable name and a data file.  Use @CreateAProcess().

Correction: CreateAProcess() does not use the "@" symbol.
« Last Edit: Feb 21st, 2011 at 2:44pm by The Cow »  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged