1

I have a bunch of Powershell scripts which I need to run from Perl. I have the following code but for some reason the Powershell scripts dont get invoked. I have tried both the backtick and the system command

$path = "C:/Users/PSScript.ps1";
$pwspath = "c:/windows/system32/windowspowershell/v1.0/powershell.exe";

$output = `$pwspath -command $path`;

system($pwspath -command $path);

Please help me out here.

2
  • Hint: try adding use strict; use warnings; to the top of your script and try again. Commented May 5, 2010 at 2:17
  • Are you sure you want backticks? Backticks are used to capture what is printed to console output as a result of running the command. system is more appropriate for invoking scripts. Commented May 5, 2010 at 10:20

2 Answers 2

1

You need to use -File instead of -Command

Sign up to request clarification or add additional context in comments.

Comments

0

Are you sure your code is formatted correctly? Shouldn't you be using quotes?

system("$pwspath -command $path");

Backtick should work, try:

my @stdout = `$pwspath -command $path`;
print join("\n", @stdout),"\n";

1 Comment

hi, system() works but backtick doesnt tried the following "$pwspath -command $path"; system("$pwspath -command $path") any ideas for backtick, since I need to capture the stdout and then format it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.