skip to Main Content

When I am running a python program for example :

print("hello world")

I get too many texts in the terminal (VS Code)

Windows PowerShell
Copyright (C) 2015 Microsoft Corporation. All rights reserved.

PS C:UsersDimuth De ZoysaDesktopPython_projects> & "C:/Users/Dimuth De Zoysa/AppData/Local/Programs/Python/Python38/python.exe" "c:/Users/Dimuth De Zoysa/Desktop/Python_projects/main.py"
hello world
PS C:UsersDimuth De ZoysaDesktopPython_projects>

But I really wanted is something like this :

hello world

So, How can I remove those paths & nonsense text ?

2

Answers


  1. Try following which will skip the first two lines and then print lines that do not start with a PS

    $filename = 'c:temptest.txt'
    
    $filteredData = Get-Content -path $filename | Select-Object -skip 2 | Select-String -NotMatch "^PS"
    $filteredData
    
    Login or Signup to reply.
  2. First of all, they are not meaningless text, they show the execution command of the script file, which can also ensure that the script can be executed normally in any directory. We should get used to the way it works.

    If you must get clean output, install the Code Runner extension, add the following to the settings.json, and execute the script with Run COde

        "code-runner.runInTerminal": false,
        "code-runner.clearPreviousOutput": true,
        "code-runner.showExecutionMessage": false,
    

    enter image description here

    If there is no special need, please do not use Code Runner. Using Python extensions is the best way.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search