[ProcessLibrary] Log result from PowerShell command

Hello everyone,

I use a PowerShell command in RobotFramework, and I want to send the result of my command in a file.

I added " > myfile.txt" in the end of my command, there is no problem when I do it manually, my file is created with the good result inside.

But when I run this same command in RobotFramework, my file is created but empty

Can anyone help me please?

Thank you!

Hi @Brahim1991,

Are you are using Run Process? If so, you probably want to not use > myfile.txt but rather stdout=myfile.txt (see the Process configuration link in Run Process help). if you don’t actually need the result in a file, just need to test the output you might want to look at ${result.stdout} also mentioned in the documentation.

Otherwise can you show us what your trying to do so we can guide you better.

Dave.

:frowning: quote=“damies13, post:2, topic:5352”]
stdout
[/quote]

Hi @damies13 , and than you for your response.

Yes I use Run Process as this :

Run Process Powershell.exe -Command [convert]::ToBase64String((Get-Content -path “C:\Users\BB\PycharmProjects\pythonProject\resources\xml\String_Linearise_01.txt” -Encoding byte)) stdout=encoded.txt #shell=true

I also tried without commenting shell=true, in the two cases my file is created bt empty :frowning:

I found a solution : I created a .ps1 file with my command inside, and I call it from RobotFramework as :

run process Powershell.exe ${CURDIR}${/}b64.ps1

Thank you for your help :slight_smile:

1 Like

Hi All,
I created one powershell script for uninstalling postgresql
and trying to run from robotframe work file .The testcase is passed but postqresql is not uninstalled.

*** Settings ***
Library Process
*** Variables ***
${uninstallerPath} C:\Users\Ps\Downloads\powershell\uninstall-postgresql.ps1
*** Test Cases ***
Uninstall PostgreSQL
${result}= Run Process powershell.exe -File ${uninstallerPath} shell=$True
Any idea on how tonrun powershell scrit from robot framework

Hi Surekha,

Did you esacape the \ as \\? ( Escaping)

Dave.

Hi @damies13
sorry i i used \ only
*** Settings ***
Library Process
*** Variables ***
${uninstallerPath} C:\Users\Ps\Downloads\powershell\uninstall-postgresql.ps1
*** Test Cases ***
Uninstall PostgreSQL
${result}= Run Process powershell.exe -File ${script_path} shell=$True

Hi Surekha,

In robot framework (and in most programming languages you need to escape the \ character, it’s because a reserved character. The link I gave you is where it tells you that in the documentation.

Dave.

1 Like

Hi @damies13
I tried with double backslashes .Its typo mistake
In my Pc running PowerShell scripts restricted.
i changed that now its working

1 Like