Solved

PHP & Powershell

Posted on 2013-05-21
3
304 Views
Last Modified: 2013-05-29
Hi guys,

I'm using PHP to run a Powershell script in an external file. The script runs, pulls some information from a database, and then writes the info to a txt file. This is working fine.

Now instead of writing the info into a text file, I want to pass it back the PHP page as an array,

Any suggestions of how I can do this?

Cheers,
0
Comment
Question by:gesmuk
3 Comments
 
LVL 20

Expert Comment

by:Mark Brady
Comment Utility
Hmm not sure if you can do that exactly but you could let the script finish executing then open the log file with php and read it into an array. Depends on how you are calling the external script. If you are opening a powershell and typing php filename.php then you can edit that file and have it create the array and output it to the screen or var_dump($array); and you would see what is in the array that way.

Other than that you would need to have another php script which calls the first script and when it is finished, open the log file and read the data.
0
 
LVL 6

Accepted Solution

by:
Robert Saylor earned 500 total points
Comment Utility
Why not write data to a text file from powershell then read that file back into PHP? Flat file database might be the best option. If powershell supports mysql then you could use mysql as your mediation layer.

php from the command prompt also supports arguments. So if powershell can execute a php script you could then pass data back into a php script.

script.php arg1 arg2 arg3

The variable should be $argv[0] , $argv[1], etc in code

Example: Note (The first argv will be the php filename so your data would start with $argv[1])

<?php

print $argv[0] . "\n";
print $argv[1] . "\n";
print $argv[2] . "\n";
print $argv[3] . "\n";

?>

Open in new window


root@linux [~]# php test.php Expert Exchange PHP
test.php
Expert
Exchange
PHP

Open in new window

0
 

Author Comment

by:gesmuk
Comment Utility
Thanks guys, went for the method of writing the result to a text file and reading it back in. A little dirty, but get's the result!

Cheers,
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 look for a specific file type in a local or remote server directory using PHP.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now