Python Forum
export file and display cmd prompt same time
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
export file and display cmd prompt same time
#1
Do anyone know how to export the log file? i run this script, it will run on the cmd prompt but i also wish to log on a file. Is there nay possible method to export on a file in the same time wit will show on the prompt.

This is my script
import os
import time
import datetime
count=0
cycle=1000
now = datetime.datetime.now()

hostname_IP = input("enter your ip address(host):")
cycle = input("please enter how many cycle?(default is 1000) ")
cycle = int(cycle)
print ("==================start==============")
print ("===============Current date and time : ",time.strftime("%a, %d %b %Y %H:%M:%S"),"===============")
for i in range (cycle):
    response = os.system("ping -n 5 " + hostname_IP  + " | FIND " + '"TTL="')
    	 
    time.sleep(60)
    if response == 0:
   
        count =count+1

        
       
        print ("###result:PASS###",count)
    else:
        print ("result:FAIL")
        break


    print ("==================end==============")
os.system("pause")
Reply
#2
There's a built in logger you can use, see: https://docs.python.org/3/library/logging.html
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to display <IPython.core.display.HTML object>? pythopen 3 45,711 May-06-2023, 08:14 AM
Last Post: pramod08728
  How to keep columns header on excel without change after export data to excel file? ahmedbarbary 0 1,130 May-03-2022, 05:46 PM
Last Post: ahmedbarbary
  Real time Detection and Display Gilush 0 1,764 Feb-05-2022, 08:28 PM
Last Post: Gilush
  Facing Problem while opening a file through command prompt vlearner 4 1,857 Jan-30-2022, 08:10 AM
Last Post: snippsat
  Check last time file was accessed Pavel_47 4 2,761 Jun-01-2021, 05:47 PM
Last Post: Yoriz
  find the header location in a .bin file without reading the whole file at a time SANJIB 0 2,189 Mar-05-2021, 04:08 PM
Last Post: SANJIB
  Yahoo_fin question: how does one export all stock tickers to a csv file detlefschmitt 9 8,622 Feb-12-2021, 07:46 AM
Last Post: detlefschmitt
  Naming the file as time and date. BettyTurnips 3 2,891 Jan-15-2021, 07:52 AM
Last Post: BettyTurnips
  how to change the range of read CSV file every time python file runs greenpine 6 4,382 Dec-08-2020, 10:11 PM
Last Post: greenpine
  Skeleton file export error Python Code pepapoha 4 3,428 Nov-17-2020, 02:06 AM
Last Post: pepapoha

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020