Query with RunProgram()
Query with RunProgram()
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
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
Re: Query with RunProgram()
What combinations specifically? And, by any chance, is this on a Mac?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 !!
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 

Re: Query with RunProgram()
Can you post the RunProgram() line that you're using?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 !!
Re: Query with RunProgram()
Windows 7 sp1
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
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
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
Re: Query with RunProgram()
No leading drive letter and colon? Or is it a network path? I don't think RunProgram() supports network paths.Neil wrote:sCommand = "\\r-abcdef\Launcher\Freedom Launcher Batch2015.bat"
Try this instead to see if it works better (for Windows only):
Code: Select all
iResult=ShellExecute_(0,"open",sCommand,sString,"",#SW_SHOW)
Code: Select all
iResult=ShellExecute_(0,"open",sCommand,sString,GetPathPart(sCommand),#SW_SHOW)
Re: Query with RunProgram()
Yes this is a network path.Dude wrote:No leading drive letter and colon? Or is it a network path? I don't think RunProgram() supports network paths.Neil wrote:sCommand = "\\r-abcdef\Launcher\Freedom Launcher Batch2015.bat"
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.
Re: Query with RunProgram()
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
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
Re: Query with RunProgram()
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:
You can also try in your batch script to add :
This will pause the script - I would add this at the beginning to make sure the batch is being started.
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
Code: Select all
echo Running
timeout /t -1
----
R Tape loading error, 0:1
R Tape loading error, 0:1
Re: Query with RunProgram()
in batch "pause" command also
Re: Query with RunProgram()
Hi All,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 !!
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).
Re: Query with RunProgram()
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 variableNeil 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
Re: Query with RunProgram()
I had already added GetcurrentDirectory() to my application to see what the current directory was.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
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 ??
Re: Query with RunProgram()
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?
Out of curiosity, did you try ShellExecute instead to see if it's more reliable than RunProgram?
Re: Query with RunProgram()
When/how does RunProgram() open a folder ??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.
I couldn't see any details about that in manual.
Not yet - I would like to find the cause of RunProgram() functioning the way it is (opening a folder) and sort that out.Dude wrote:Out of curiosity, did you try ShellExecute instead to see if it's more reliable than RunProgram?
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.
Re: Query with RunProgram()
It's just a wrapper to ShellExecute, so it works. Like this:Neil wrote:When/how does RunProgram() open a folder ??
Code: Select all
RunProgram("c:\") ; Opens the C: folder.
RunProgram("http://www.purebasic.com") ; Opens PureBasic.com.