Solved

PHP & Powershell

Posted on 2013-05-21
3
332 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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Nested ForEach in Powershell 4 17
PS call executable Files in Order 4 15
..ignore the Question 1 9
php error 26 28
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article will help you understand what HashTables are and how to use them in PowerShell.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

828 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