Calling MS-Windows associated file to run the Windows progra

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bowlesj
Forum Contributor
Posts: 179
Joined: Fri Jul 18, 2014 1:54 pm

Calling MS-Windows associated file to run the Windows progra

Post by bowlesj »

Hi, I am trying to (either with Javascript or with PHP or both for that matter) (while running under XAMPP) call/open a file which is associated with a Windows program such that the windows program is called to read/process the file. In my case the windows program is "Band In A Box" and the file can be any file that "Band In A Box" typically runs. Does anyone know where I can get some examples of how to do this.

To give you an idea of what I am hoping for, In MS-Access the command is shown below ("Me.fldS_BIAB_File" contains the file name).
Application.FollowHyperlink "C:\Access\BIAB\" & Me.fldS_BIAB_File, , True
or
'MyAppID = Shell("C:\Program Files (x86)\Microsoft Office\Office12\Excel.exe C:\Access\MyExcellFile", vbMaximizedFocus)

I tried this google search "opening a windows associated file with javascript" and 'opening a windows associated file with php" but they come back with opening php files.



Thanks,
John
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Calling MS-Windows associated file to run the Windows pr

Post by requinix »

Javascript cannot do it at all. If you want to open a file on the server then PHP can do it. But I assume you want to open the file on the client?

It's not possible.
bowlesj
Forum Contributor
Posts: 179
Joined: Fri Jul 18, 2014 1:54 pm

Re: Calling MS-Windows associated file to run the Windows pr

Post by bowlesj »

I will be running the php code on my notebook computer using XAMPP. The "Band In A Box" file and the BIAB program will be on the notebook computer as well. So it sounds like it can be done. I was going to try the php fopen command but then I decided to do a google search "php shell command" and found this.
http://php.net/manual/en/function.shell-exec.php

Well I got the BIAB program to run with this command. Now all I have to do is figure out how to submit different files via a variable.
bowlesj
Forum Contributor
Posts: 179
Joined: Fri Jul 18, 2014 1:54 pm

Re: Calling MS-Windows associated file to run the Windows pr

Post by bowlesj »

I got the test to work. It seems to be just as fast as calling the file from MS-Access. I had to change the file separators to forward slashes to get it to work because the last backslash was escaping the single quote character. It looks better if they are all consistent.
$InputFile="BIAB_SONG_FILE.MGU";
$MyCommand='F:/bb/bbw.exe C:/BIAB_SongFiles/' . $InputFile;
$output = shell_exec($MyCommand);
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Calling MS-Windows associated file to run the Windows pr

Post by requinix »

Yes, that's one of the ways to do it. shell_exec, exec, passthru, system, proc_* and p* functions... Some of those are more appropriate than others if you want to capture output or get detailed process information.

Most people have issues running programs at all - mostly about permissions - but if the backslashes were the only difficulty you had then that's great.
Post Reply