Solved

PHP & Powershell

Posted on 2013-05-21
3
324 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
ID: 39185158
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 7

Accepted Solution

by:
Robert Saylor earned 500 total points
ID: 39185190
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
ID: 39204680
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Set OWA language and time zone in Exchange for individuals, all users or per database.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

775 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