Solved

PHP & Powershell

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

Technology Partners: 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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

734 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