Query with RunProgram()

Just starting out? Need help? Post your questions and find answers here.
Neil
Enthusiast
Enthusiast
Posts: 198
Joined: Wed Feb 29, 2012 8:04 am
Location: Melbourne, AUS

Query with RunProgram()

Post by Neil »

Before I spend time submitting code etc, I was wondering if there might be a simple explanation for my problem.

I have a menu type application that allows a user to select which program to run for a selected job/project.

My application calls the RunProgram() function.

Generally this works fine, but in some selection combinations, instead of the selected program being launched, the application just opens the directory where the application files are stored !!

Thanks,

Neil
User avatar
TI-994A
Addict
Addict
Posts: 2698
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Query with RunProgram()

Post by TI-994A »

Neil wrote:...but in some selection combinations, instead of the selected program being launched, the application just opens the directory where the application files are stored !!
What combinations specifically? And, by any chance, is this on a Mac?
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Query with RunProgram()

Post by Dude »

Neil wrote:in some selection combinations, instead of the selected program being launched, the application just opens the directory where the application files are stored !!
Can you post the RunProgram() line that you're using?
Neil
Enthusiast
Enthusiast
Posts: 198
Joined: Wed Feb 29, 2012 8:04 am
Location: Melbourne, AUS

Re: Query with RunProgram()

Post by Neil »

Windows 7 sp1

Code: Select all

    iResult =  RunProgram(sCommand, sString, "")
    If iResult = 0
       MessageRequester("Runtime Error","Navisworks option:  " + sCommand + " is not available for this project",#PB_MessageRequester_Ok )
    EndIf    
where:
sCommand = "\\r-abcdef\Launcher\Freedom Launcher Batch2015.bat"
sString = "ABC" where ABC is the project code

Note that application does not display an error, i.e. iResult <> 0
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Query with RunProgram()

Post by Dude »

Neil wrote:sCommand = "\\r-abcdef\Launcher\Freedom Launcher Batch2015.bat"
No leading drive letter and colon? Or is it a network path? I don't think RunProgram() supports network paths.

Try this instead to see if it works better (for Windows only):

Code: Select all

iResult=ShellExecute_(0,"open",sCommand,sString,"",#SW_SHOW)
If not, try this one (again, Windows only):

Code: Select all

iResult=ShellExecute_(0,"open",sCommand,sString,GetPathPart(sCommand),#SW_SHOW)
Neil
Enthusiast
Enthusiast
Posts: 198
Joined: Wed Feb 29, 2012 8:04 am
Location: Melbourne, AUS

Re: Query with RunProgram()

Post by Neil »

Dude wrote:
Neil wrote:sCommand = "\\r-abcdef\Launcher\Freedom Launcher Batch2015.bat"
No leading drive letter and colon? Or is it a network path? I don't think RunProgram() supports network paths.
Yes this is a network path.

As I mentioned in my first post though, this command generally works ok.
It only "fails" if the user has chosen the "other" program first.

I don't know if this is the issue, but when the "other" program runs, the batch file that launches that particular program changes to a specific directory.
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Query with RunProgram()

Post by infratec »

Hi,

if you run a bat file, maybe a call to cmd.exe is a better way.
And then look here for UNC file path:
http://ss64.com/nt/cmd.html

Bernd
User avatar
em_uk
Enthusiast
Enthusiast
Posts: 366
Joined: Sun Aug 08, 2010 3:32 pm
Location: Manchester UK

Re: Query with RunProgram()

Post by em_uk »

Hello.

Running batch scripts from a network drive will complain about UNC paths. You script is probably running OK but failing at a batch level.

You can (in batch) pushd a network drive which will map and then change to that directory, then use popd to remove the drive. I find batch scripts can be very temperamental when ran directly on the network drive. eg:

Code: Select all

pushd \\network\location

echo all my batch commands

popd
You can also try in your batch script to add :

Code: Select all

echo Running
timeout /t -1
This will pause the script - I would add this at the beginning to make sure the batch is being started.
----

R Tape loading error, 0:1
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: Query with RunProgram()

Post by Keya »

in batch "pause" command also
Neil
Enthusiast
Enthusiast
Posts: 198
Joined: Wed Feb 29, 2012 8:04 am
Location: Melbourne, AUS

Re: Query with RunProgram()

Post by Neil »

Neil wrote: My menu application calls the RunProgram() function.
Generally this works fine, but in some selection combinations, instead of the selected program being launched, the menu application just opens the directory where the menu application files are stored !!
Hi All,
Thanks you for your time and suggestions, but what I was hoping for was for someone to know why the RunProgram() function sometimes works as I describe.
I am not looking for "workarounds", as I cannot change how the programs I am selecting are launched.
I do not think the the behavior is not caused by the unc path, as generally the RunProgram() function works as expected using the unc path and I cannot change this.
Also I cannot change the batch file used to call the other program (and this program launches fine anyway).
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: Query with RunProgram()

Post by Keya »

Neil wrote:As I mentioned in my first post though, this command generally works ok.
It only "fails" if the user has chosen the "other" program first
perhaps the other program is changing something like the current working directory which a call to SetCurrentDirectory() might fix, or less likely perhaps its changing an environment variable
Neil
Enthusiast
Enthusiast
Posts: 198
Joined: Wed Feb 29, 2012 8:04 am
Location: Melbourne, AUS

Re: Query with RunProgram()

Post by Neil »

Keya wrote:perhaps the other program is changing something like the current working directory which a call to SetCurrentDirectory() might fix, or less likely perhaps its changing an environment variable
I had already added GetcurrentDirectory() to my application to see what the current directory was.

This reported back the directory of the Application's files (which was as expected).

I have now added SetCurrentDirectory() to the code and set it to the directory returned by GetCurrentDirectory()

This does seem pointless, but at the moment the application is working, so I will monitor and see what happens !!

I am still interested to know the reason behind the behavior I reported - i.e. why does RunCommand() just open the current directory - in this case where the applications's files are ??
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Query with RunProgram()

Post by Dude »

RunProgram() can be used to run a program, open a folder, open a document, or open a web page. It's nothing unusual.

Out of curiosity, did you try ShellExecute instead to see if it's more reliable than RunProgram?
Neil
Enthusiast
Enthusiast
Posts: 198
Joined: Wed Feb 29, 2012 8:04 am
Location: Melbourne, AUS

Re: Query with RunProgram()

Post by Neil »

Dude wrote:RunProgram() can be used to run a program, open a folder, open a document, or open a web page. It's nothing unusual.
When/how does RunProgram() open a folder ??
I couldn't see any details about that in manual.
Dude wrote:Out of curiosity, did you try ShellExecute instead to see if it's more reliable than RunProgram?
Not yet - I would like to find the cause of RunProgram() functioning the way it is (opening a folder) and sort that out.
As I have said - if I just launch the selected program as the first option when running my menu application, everything works fine.
If is only if I launch the other program first does RunProgram() open the folder.
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Query with RunProgram()

Post by Dude »

Neil wrote:When/how does RunProgram() open a folder ??
It's just a wrapper to ShellExecute, so it works. Like this:

Code: Select all

RunProgram("c:\") ; Opens the C: folder.
RunProgram("http://www.purebasic.com") ; Opens PureBasic.com.
Post Reply