Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PHP & Powershell

Posted on 2013-05-21
3
Medium Priority
?
358 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
[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
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 1000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

618 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