Page 1 of 2
Query with RunProgram()
Posted: Mon Nov 23, 2015 3:05 am
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
Re: Query with RunProgram()
Posted: Mon Nov 23, 2015 3:37 am
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?
Re: Query with RunProgram()
Posted: Mon Nov 23, 2015 4:06 am
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?
Re: Query with RunProgram()
Posted: Mon Nov 23, 2015 4:45 am
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
Re: Query with RunProgram()
Posted: Mon Nov 23, 2015 5:13 am
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)
Re: Query with RunProgram()
Posted: Mon Nov 23, 2015 7:17 am
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.
Re: Query with RunProgram()
Posted: Mon Nov 23, 2015 8:22 am
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
Re: Query with RunProgram()
Posted: Tue Nov 24, 2015 1:19 am
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 :
This will pause the script - I would add this at the beginning to make sure the batch is being started.
Re: Query with RunProgram()
Posted: Tue Nov 24, 2015 1:31 am
by Keya
in batch "pause" command also
Re: Query with RunProgram()
Posted: Tue Nov 24, 2015 2:54 am
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).
Re: Query with RunProgram()
Posted: Tue Nov 24, 2015 3:08 am
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
Re: Query with RunProgram()
Posted: Wed Nov 25, 2015 3:42 am
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 ??
Re: Query with RunProgram()
Posted: Wed Nov 25, 2015 8:40 am
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?
Re: Query with RunProgram()
Posted: Sat Nov 28, 2015 9:15 am
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.
Re: Query with RunProgram()
Posted: Sat Nov 28, 2015 10:14 am
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.