MSFN Forum: yanklines - MSFN Forum

Jump to content


  • 3 Pages +
  • 1
  • 2
  • 3
  • You cannot start a new topic
  • You cannot reply to this topic

yanklines is it possible to run it in background? Rate Topic: -----

#1 User is offline   tomasz86 

  • http://www.windows2000.tk
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,220
  • Joined: 27-November 10
  • OS:Windows 2000 Professional
  • Country: Country Flag

Posted 08 August 2011 - 11:15 PM

I wonder if it's possible to run yanklines.vbs totally in background without any console windows popping up.

Here is the part of the code which is responsible for this behaviour:

'Create a persistent command prompt for the cscript output window and call the script with its original arguments    
                scriptCommand = "cmd.exe /k " & engineFolder & "cscript.exe """ & Wscript.ScriptFullName & """" & argString


By changing

cmd.exe /k

to

cmd.exe /c

I managed to get it closed as soon as it pops up. What I would like to do is to prevent any windows from being displayed while running the script.


#2 User is offline   allen2 

  • Not really Newbie
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 1,733
  • Joined: 13-January 06

Posted 08 August 2011 - 11:54 PM

You need :
- to comment the line
RunMeWithCScript()

- to comment all lines with wscript.echo (unless you want popup for each line).
- to launch the script with wscript.exe instead of cscript if you're launching it from another script.

This post has been edited by allen2: 08 August 2011 - 11:58 PM


#3 User is offline   tomasz86 

  • http://www.windows2000.tk
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,220
  • Joined: 27-November 10
  • OS:Windows 2000 Professional
  • Country: Country Flag

Posted 29 February 2012 - 12:39 AM

It's a late reply but...

as I don't know anything about VBS scripting I tried a different method:

1) I downloaded hidcon.
2) I changed

'Create a persistent command prompt for the cscript output window and call the script with its original arguments    
                scriptCommand = "cmd.exe /k " & engineFolder & "cscript.exe """ & Wscript.ScriptFullName & """" & argString

to
'Create a persistent command prompt for the cscript output window and call the script with its original arguments    
                scriptCommand = "hidcon.exe cmd.exe /k " & engineFolder & "cscript.exe """ & Wscript.ScriptFullName & """" & argString


Everything is run in background now.

#4 User is offline   tomasz86 

  • http://www.windows2000.tk
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,220
  • Joined: 27-November 10
  • OS:Windows 2000 Professional
  • Country: Country Flag

Posted 05 March 2012 - 11:22 AM

By the way, does anyone know how to make the script case insesitive?

#5 User is offline   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,351
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 05 March 2012 - 12:08 PM

Could you post the part of the script that you want to make case insensitive

#6 User is offline   tomasz86 

  • http://www.windows2000.tk
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,220
  • Joined: 27-November 10
  • OS:Windows 2000 Professional
  • Country: Country Flag

Posted 05 March 2012 - 10:40 PM

Well, I'd just like the script to remove all duplicates regardless of their case. I don't know which part of yanklines is responsible for this...

#7 User is offline   tomasz86 

  • http://www.windows2000.tk
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,220
  • Joined: 27-November 10
  • OS:Windows 2000 Professional
  • Country: Country Flag

Posted 06 March 2012 - 08:06 AM

The duplicate lines I'm talking about are something like these:

 CopyFiles = System32.files
 CopyFiles = System32.Files
 CopyFiles = Fonts.Files
 CopyFiles = Fonts.files


#8 User is offline   dencorso 

  • Adiuvat plus qui nihil obstat
  • Group: Super Moderator
  • Posts: 4,862
  • Joined: 07-April 07
  • OS:98SE
  • Country: Country Flag

Posted 09 March 2012 - 12:29 AM

Locate this:

Set objDict = CreateObject("Scripting.Dictionary")
j = 0

and change it thus:

Set objDict = CreateObject("Scripting.Dictionary")
objDict.CompareMode = 1 'Text i.e. case insensitive
j = 0

I'd also keep the "cmd /c" instead of "cmd /k" like you did in your first post, in addition to using hidcon.

PS: setting:

objDict.CompareMode = 0 'Binary i.e. case sensitive

would restore case sensitivity.

However, making it case insensitive does not ensure a consistent casing... Your example above results in:

CopyFiles = System32.files
CopyFiles = Fonts.Files

because always the first occurence is the one preserved, regardless of casing, so do take care.

#9 User is offline   tomasz86 

  • http://www.windows2000.tk
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,220
  • Joined: 27-November 10
  • OS:Windows 2000 Professional
  • Country: Country Flag

Posted 11 March 2012 - 01:16 AM

Thank you very much. Fortunately in this case it doesn't matter whether casing is consistent or not.

#10 User is offline   dencorso 

  • Adiuvat plus qui nihil obstat
  • Group: Super Moderator
  • Posts: 4,862
  • Joined: 07-April 07
  • OS:98SE
  • Country: Country Flag

Posted 11 March 2012 - 11:05 PM

Since I think the case-insensitive version is more useful than the previous one, I've updated my original Yanklines.VBS post, to reflect this. Thanks for calling my attention to the problem!

#11 User is online   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,420
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 12 March 2012 - 02:25 AM

View Postdencorso, on 11 March 2012 - 11:05 PM, said:

Since I think the case-insensitive version is more useful than the previous one, I've updated my original Yanklines.VBS post, to reflect this. Thanks for calling my attention to the problem!

With all due respect :), the idea of updating is generally to "better" in the sense of "adding features/choices" or correct "wrong" behaviour, wouldn't it be more desirable to have a /I command line parameter/switch (not entirely unlike the batch IF /I one)?
(or reversing the default a /CS one)?

jaclaz

#12 User is offline   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,351
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 12 March 2012 - 12:09 PM

Here is a script I wrote that will remove duplicate lines and blank lines from INI INF TXT file types. You can use this script 2 ways

1:\ Drag and Drop the file onto the script

2:\ Cmd Line

Quote

cscript %UserProfile%\Desktop\RemoveLines.vbs D:\MyTemp\Test1.Txt


This will then produce a file called New_FileName.Extension

Test File Contents

Quote

[Section 01 Test]
Line 01 Test
LINE 01 TEST
LINE 01 Test
Line 01 TEST
line 01 test
lINE 01 tEST
Line 01 Test
LINE 01 TEST
LINE 01 Test
Line 01 TEST
line 01 test
lINE 01 tEST
[Section 02 Test]
Line 02 Test

Line 02 Test
[Section 03 Test]

Line 03 Test
Line 02 Test


[Section 04 Test]

Line 04 Test
Line 03 Test

[Section 05 Test]
Line 05 Test 1

Line 05 Test 2
[Section 06 Test]



Line 06 Test
Line 03 Test


Results Of Script

Quote

[Section 01 Test]
Line 01 Test
[Section 02 Test]
Line 02 Test
[Section 03 Test]
Line 03 Test
[Section 04 Test]
Line 04 Test
[Section 05 Test]
Line 05 Test 1
Line 05 Test 2
[Section 06 Test]
Line 06 Test


Save As RemoveLines.vbs
Dim Dic :Set Dic = CreateObject("Scripting.Dictionary")
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
'-> Drag One File
  If WScript.Arguments.Count = 1 Then
'-> Process INF, INI,TXT
   Select Case LCase(Right(WScript.Arguments.Item(0),3))
    Case "inf","ini","txt"
    TextChange(WScript.Arguments.Item(0))
    Case Else 
'-> Not Correct File Type
    MsgBox "This file is not a valid file type : " & _
    Right(WScript.Arguments.Item(0),3) & vbCrLf & _
    "Drag And Drop These Types INF INI TXT",4128,_
    "Error Wrong File Type"
    WScript.Quit
   End Select 
'-> No File Drag
  ElseIf WScript.Arguments.Count = 0 Then
   ErrorMsg("Error File Total : " & WScript.Arguments.Count)
'-> To Many Files Drag
  ElseIf WScript.Arguments.Count >= 2 Then
   ErrorMsg("Error File Total : " & WScript.Arguments.Count)
  End If 
'-> Function To Handle To Many Or Zero Files
   Function ErrorMsg(N)
    MsgBox _
     "There must be only 1 Text File Type Drag And Drop" & vbCrLf & _
     "onto this script. " & N,4128, N
    WScript.Quit
   End Function
'-> Remove Duplicate Lines
   Function TextChange(File)
    Dim Ts, Tx
    Set File = Fso.GetFile(File)
    Set Ts = Fso.OpenTextFile(File.Path)
'-> 1 = Case Insensitive , 0 = Case Sensitive
    Dic.CompareMode = 1
     Do Until Ts.AtEndOfStream
      Tx = Ts.ReadLine 
      If Not Dic.Exists(Tx) Then Dic.Add Tx, Tx 
     Loop 
    Ts.Close 
    Set Ts = Fso.CreateTextFile( _
    Replace(File.Path,File.Name, "New_" & File.Name))
    For Each Tx In Dic.Keys
     If Not Tx = "" Then Ts.WriteLine Tx
    Next 
    Ts.Close
   End Function 



Sorry for the double attach file I am on Windows 8 and I can not remove one from the post,
the site not quite right on Win 8

#13 User is offline   dencorso 

  • Adiuvat plus qui nihil obstat
  • Group: Super Moderator
  • Posts: 4,862
  • Joined: 07-April 07
  • OS:98SE
  • Country: Country Flag

Posted 12 March 2012 - 06:19 PM

View Postjaclaz, on 12 March 2012 - 02:25 AM, said:

View Postdencorso, on 11 March 2012 - 11:05 PM, said:

Since I think the case-insensitive version is more useful than the previous one, I've updated my original Yanklines.VBS post, to reflect this. Thanks for calling my attention to the problem!

With all due respect :), the idea of updating is generally to "better" in the sense of "adding features/choices" or correct "wrong" behaviour, wouldn't it be more desirable to have a /I command line parameter/switch (not entirely unlike the batch IF /I one)? (or reversing the default a /CS one)?

Yes, I considered that. However, I do think the case-insensitive behaviour is in line with the general behaviour of both DOS and Windows (FIND is an exception, there must be others...) and generally more useful. Now, since to restore the original case sensitive behaviour of the script is just a matter of changing a single "1" to "0" inside the script (and it's documented by a comment at that point), I decided adding a command-line parameter to control it would be an overkill, since it would entail many lines of code for a robust parsing of the command-line, which would add unneeded complexity to the code. That's just my 2 ¢, of course.

#14 User is offline   CoffeeFiend 

  • Coffee Aficionado
  • Group: Super Moderator
  • Posts: 5,399
  • Joined: 14-July 04
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 12 March 2012 - 07:30 PM

Tasks like this (or others like sorting data) is why I'm moving away from VBScript for scripting/admin/automating stuff, mainly towards PowerShell and C#. It took over 80 lines of VBScript to do, whereas in PowerShell it's a very simple one-liner:

gc in.txt|select -unique|out-file out.txt

I have nothing to say against your script (I only had a *very* quick glance). It's the scripting technology itself that's reached the point where new offerings do the job better and quicker most of the time. So I just wanted to point out how much quicker/simpler it is now.

#15 User is offline   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,351
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 12 March 2012 - 07:57 PM

I really could not get the so called one line solution to work correctly
The only output I could was from my last try with Power Shell
Contents Of Test1.txt

Quote

[Section 01 Test]
Line 01 Test
LINE 01 TEST
LINE 01 Test
Line 01 TEST
line 01 test
lINE 01 tEST
Line 01 Test
LINE 01 TEST
LINE 01 Test
Line 01 TEST
line 01 test
lINE 01 tEST
[Section 02 Test]
Line 02 Test

Line 02 Test
[Section 03 Test]

Line 03 Test
Line 02 Test


[Section 04 Test]

Line 04 Test
Line 03 Test

[Section 05 Test]
Line 05 Test 1

Line 05 Test 2
[Section 06 Test]



Line 06 Test
Line 03 Test


PowerShell Output To New_Test1.txt

Quote

C:\Users\Gunsmokingman\Desktop\Test1.Txt

Attached File(s)



#16 User is offline   CoffeeFiend 

  • Coffee Aficionado
  • Group: Super Moderator
  • Posts: 5,399
  • Joined: 14-July 04
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 12 March 2012 - 08:46 PM

You're missing the out-file at the end (which tells it to write to a file).

Then again it could be a one-liner in so many languages... A couple quick examples:

in C# (tested), with special thanks to the LINQ's Distinct extension method who does all of the work besides the file I/O (case insensitive -- just lose the StringComparer.CurrentCultureIgnoreCase for a case sensitive version):
File.WriteAllLines(args[1], File.ReadAllLines(args[0]).Distinct(StringComparer.CurrentCultureIgnoreCase));


or for those who still do VB in 2012 (not tested):
File.WriteAllLines(args(1), File.ReadAllLines(args(0)).Distinct(Of String)(StringComparer.CurrentCultureIgnoreCase))


Of course I'd add a couple simple guard clauses (args.Length != 2 to show usage, and File.Exist on the source file) and ideally also a try/catch block for the file IO (if this was more than a quickie) but essentially that's all of the relevant code right there.

#17 User is offline   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,351
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 12 March 2012 - 09:04 PM

I did get it to work with this line
gc "C:\Users\Gunsmokingman\Desktop\Test1.Txt" | select -unique | out-file "C:\Users\Gunsmokingman\Desktop\New_Test1.Txt"


Output File Contents

Quote

[Section 01 Test]
Line 01 Test
LINE 01 TEST
LINE 01 Test
Line 01 TEST
line 01 test
lINE 01 tEST
[Section 02 Test]
Line 02 Test

[Section 03 Test]
Line 03 Test
[Section 04 Test]
Line 04 Test
[Section 05 Test]
Line 05 Test 1
Line 05 Test 2
[Section 06 Test]
Line 06 Test

For One Line it works ok, but what changes would be needed to make it case insensitive.

#18 User is offline   CoffeeFiend 

  • Coffee Aficionado
  • Group: Super Moderator
  • Posts: 5,399
  • Joined: 14-July 04
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 12 March 2012 - 09:46 PM

View Postgunsmokingman, on 12 March 2012 - 09:04 PM, said:

what changes would be needed to make it case insensitive

More than you'd want really (I'd be using a hashset[string] instead, so more like 5 lines). That's why when the scope of the project start to fall outside of what powershell does best I switch to other tools. For example, see the C#/VB one-liners (both case insensitive) in the post directly above yours. There are plenty more options out there that don't need 80+ lines for such a simple task. My point isn't so much to solve this particular problem (yanklines already works for him, no point in me wasting time on a already solved problem) but rather that there are so many other options out there. Then again, if I was working on whatever he's doing (I believe merging inf files or somesuch) I'd look at solving the problem as a whole instead of just working on this script. I probably would have if the problem and solution were well defined.

#19 User is online   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,420
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 13 March 2012 - 04:29 AM

View Postdencorso, on 12 March 2012 - 06:19 PM, said:

Yes, I considered that. However, I do think the case-insensitive behaviour is in line with the general behaviour of both DOS and Windows (FIND is an exception, there must be others...) and generally more useful. Now, since to restore the original case sensitive behaviour of the script is just a matter of changing a single "1" to "0" inside the script (and it's documented by a comment at that point), I decided adding a command-line parameter to control it would be an overkill, since it would entail many lines of code for a robust parsing of the command-line, which would add unneeded complexity to the code. That's just my 2 ¢, of course.

I see :thumbup: maybe then, having TWO files:
  • yanklinesCI.vbs
  • yanklinesCS.vbs

could be handy. :unsure:

jaclaz

#20 User is offline   dencorso 

  • Adiuvat plus qui nihil obstat
  • Group: Super Moderator
  • Posts: 4,862
  • Joined: 07-April 07
  • OS:98SE
  • Country: Country Flag

Posted 13 March 2012 - 11:21 AM

Done. Thanks! :thumbup

Share this topic:


  • 3 Pages +
  • 1
  • 2
  • 3
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2013 msfn.org
Privacy Policy