Help needed in printing the text


  1. Posts : 36
    windows7 64 bit
       #1

    Help needed in printing the text


    Hello Friends,

    I am having bunch of url and trying to check whihc url has broken. Finlly endup with creating powershell command. below the code working fine.
    Code:
    @echo off
    powershell -command "gc 'links.txt'|%%{if($(try{[int][Net.WebRequest]::Create($_).GetResponse().Statuscode}Catch{}) -eq 200){$_}}|sc 'True_URL.txt'"
    pause
    But, Is there any way to print the running url? Right now i don't see what's happening on the screen. it's blank. But the process is running. I would like see which url is getting checked. Any suggestion please,
    thanks
      My Computer


  2. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #2

    Hi there,

    This should do,
    Code:
    @powershell "gc 'links.txt'|%%{'Processing: '+$_;if($(try{[int][Net.WebRequest]::Create($_).GetResponse().Statuscode}Catch{}) -eq 200){$_|ac 'True_URL.txt'}}"
    pause
    Last edited by Pyprohly; 07 Sep 2015 at 09:02. Reason: Removed code colours
      My Computer


  3. Posts : 36
    windows7 64 bit
    Thread Starter
       #3

    Hi PYP,

    Thanks and it worked. But this process is dead slow and is there any better way to achieve this functionality. i have 100*1000 url's in text file.

    Thanks
      My Computer


  4. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #4

    I thought it was a little sluggish. The line you gave me fails to release the object returned by the GetResponse method. Bad memory leaks.

    Try this,
    Code:
    @powershell "gc 'links.txt'|%{'Processing: '+$_;try{$r=[Net.WebRequest]::Create($_).GetResponse();if([int]$r.StatusCode -eq 200){$_|ac 'True_URL.txt'}}Catch{}finally{$r.Close()}}"
    Last edited by Pyprohly; 07 Sep 2015 at 09:03. Reason: Removed code colours
      My Computer


  5. Posts : 36
    windows7 64 bit
    Thread Starter
       #5

    Thanks and getting error message when i run
    The string starting:
    At line:1 char:119
    + gc 'links.txt'| '+$_;try{$r=[Net.WebRequest]::Create($_).GetResponse();if([int]$r.StatusCode -eq 200){$_|ac 'True_URL.txt <<<< '}}Catch{}finally{$r.Close()}}
    is missing the terminator: '.
    At line:1 char:149
    + gc 'mm.txt'| '+$_;try{$r=[Net.WebRequest]::Create($_).GetResponse();if([int]$r.StatusCode -eq 200){$_|ac 'True_URL.txt'}}Catch{}finally{$r.Close()}} <<<<
    + CategoryInfo : ParserError: (}}Catch{}finally{$r.Close()}}:String) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
    any suggestion please
      My Computer


  6. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #6

    Sorry, it's probably the fancy formatting I've used that was interfering with your copy-paste. I've removed the colours now.
      My Computer


  7. Posts : 36
    windows7 64 bit
    Thread Starter
       #7

    Sorry Dude, Still getting the error. am also analysis whats wrong.

    Code:
    @echo off
    @powershell "gc 'links.txt'|%{'Processing: '+$_;try{$r=[Net.WebRequest]::Create($_).GetResponse();if([int]$r.StatusCode -eq 200){$_|ac 'True_URL.txt'}}Catch{}finally{$r.Close()}}"
    pause
    output:
    The string starting:
    At line:1 char:119
    + gc 'mm.txt'| '+$_;try{$r=[Net.WebRequest]::Create($_).GetResponse();if([int]$r.StatusCode -eq 200){$_|ac 'True_URL.txt <<<< '}}Catch{}finally{$r.Close()}}
    is missing the terminator: '.
    At line:1 char:149
    + gc 'mm.txt'| '+$_;try{$r=[Net.WebRequest]::Create($_).GetResponse();if([int]$r.StatusCode -eq 200){$_|ac 'True_URL.txt'}}Catch{}finally{$r.Close()}} <<<<
    + CategoryInfo : ParserError: (}}Catch{}finally{$r.Close()}}:String) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString

    Press any key to continue . . .
      My Computer


  8. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #8

    Hm. The command line in the error message does not seem to match up with your code. Please retry that batch file.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 03:37.
Find Us