Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Run a batch script from webpage

Posted on 2013-11-07
17
Medium Priority
?
326 Views
Last Modified: 2013-11-14
My webserver is a linux box.  There is a windows server on the same domain that holds a batch file.  Wondering if there is a way to have PHP connect to that server and run that batch file.

Would like to do this via a form which would run that batch file when the button is pressed.
0
Comment
Question by:t3chguy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 7
17 Comments
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 39631528
That would be difficult.  To run a file on a different computer requires a login to that other computer.  And the user that PHP normally runs under on a web server is a very limited user that is not normally allowed outside of the web root.

You might be able to do it if you could work out all the problems with permissions and access.
0
 
LVL 1

Author Comment

by:t3chguy
ID: 39631537
I have full access to both servers so I can do whatever I need to do.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39633273
Take a step back from the technical details and just give us the business rules.  What does the batch script do?  How is its output valuable?  If you can give us the larger picture, we may be able to suggest something that will get the results you need without any "hack."
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:t3chguy
ID: 39633588
We have a rental management system that has a database back end, This batch file essentially connects to that database, pulls out the data via an ODBC connection, writes it to a table in access, then connects to my web server's database via an ODBC connection and compares the data and appends and updates when necessary.

This is essential to our business because it stores all of our company accounts that we need to access on our corporate intranet.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39633787
OK, it sounds like this is a data base synchronization question.  Couple of other questions, trying to get a sense of the flow of the data...

rental management system that has a database back end
What kind of data base is in play here?  Have you tried using PHP ODBC to connect directly to it?

writes it to a table in access
Microsoft Access?  

then connects to my web server's database
The batch file connects via ODBC?  What is the web server database?

accounts that we need to access on our corporate intranet.
Does the intranet use MS Access for its data base?
0
 
LVL 1

Author Comment

by:t3chguy
ID: 39633946
The database of the result software is Progress.  My boss informs me that we can connect directly to it using ODBC.

Correct, Microsoft Access.

The batch file runs the script that essentially opens up Microsoft Access MDB file and runs the update query.

The intranet uses MySQL for it's database.
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 39634002
It seems to me that the whole process could be done with PHP, eliminating the need for the batch file.  If there isn't a show-stopper that I'm not seeing, that is the way I would go.
0
 
LVL 1

Author Comment

by:t3chguy
ID: 39634303
Well, I found the show-stopper.

My server does not have ODBC and we let the licensing expire so I am unable to install anything, including ODBC.  We are getting new servers soon, which will fix the issue.  But until then, running that batch script is my only solution. :\
0
 
LVL 1

Author Comment

by:t3chguy
ID: 39634373
I found another server that I can use to connect:

Right now, I am getting the following error:

Notice: Undefined variable: portnumber in C:\wwwdocs\odbc.php on line 11 Warning: odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect in C:\wwwdocs\odbc.php on line 15 connection failed

$hostname = '192.168.0.99';
$portNumber = '1111';
$databaseName = 'dbname';
$username = 'user';
$password = 'pass';

$conn_string = "Driver={Progress OpenEdge 10.1C driver};
    HostName=" . $hostname . ";
    PortNumber=". $portnumber .";
    DatabaseName=" . $databaseName . ";
    DefaultIsolationLevel=READ UNCOMMITTED;";
       
$conn = odbc_connect($conn_string, $username, $password, SQL_CUR_USE_ODBC) or die("connection failed");

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39634390
PHP variable names are case-sensitive.  $portNumber != $portnumber
0
 
LVL 1

Author Comment

by:t3chguy
ID: 39634423
Dumb mistake.  Still getting Warning: odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect in C:\wwwdocs\odbc.php on line 15 connection failed Though.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39634461
Line 15?  There are only 13 lines in the code snippet.  Maybe try adding in some error visualization, for example, print out the DSN and look to see if you can discern an error.
http://php.net/manual/en/function.odbc-connect.php
http://php.net/manual/en/function.odbc-error.php
http://php.net/manual/en/function.odbc-errormsg.php
0
 
LVL 1

Author Comment

by:t3chguy
ID: 39639098
$hostname = '192.168.0.999';
$portnumber = '1111';
$databaseName = 'hr';
$username = 'userName';
$password = 'password';

$conn_string = "Driver={Progress OpenEdge 10.1C driver};
    HostName=" . $hostname . ";
    PortNumber=". $portnumber .";
    DatabaseName=" . $databaseName . ";
    DefaultIsolationLevel=READ UNCOMMITTED";
       
$conn = odbc_connect($conn_string, $username, $password, SQL_CUR_USE_ODBC) or die(odbc_errormsg());

if($conn)
	{
	echo 'Connection successful<br /><br />';

	$sql = "SELECT * FROM COGVIEWS_srnames";
			
	$res = odbc_exec($conn, $sql);

Open in new window


This returns an error stating:

Warning: odbc_exec(): SQL error: [DataDirect][ODBC Progress OpenEdge Wire Protocol driver][OPENEDGE]Table/View/Synonym not found (7519), SQL state S0002 in SQLExecDirect in C:\xampp\htdocs\odbc.php on line 21

No idea
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39639264
I think what it's saying is this:

Warning: odbc_exec(): SQL error: [DataDirect][ODBC Progress OpenEdge Wire Protocol driver][OPENEDGE] COGVIEWS_srnames not found (7519), SQL state S0002 in SQLExecDirect in C:\xampp\htdocs\odbc.php on line 21

In case it matters, the table names are almost certainly case-sensitive.
0
 
LVL 1

Author Comment

by:t3chguy
ID: 39639314
Unfortunately, that is the correct table name, with proper capitalization.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39639354
Do you have access to the SQL server so you can run commands directly (or some equivalent like phpMyAdmin)?  Maybe you can get the server to give you something?

About the only other thing I can think of is to ask the question over here.
0
 
LVL 1

Author Closing Comment

by:t3chguy
ID: 39647927
Great Solution, was able to plow my way through the rest of the script to get it fully working.

Thanks!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question