The ghostmachine4 & isacmahad Debate thread

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
ghostmachine4
Posts: 319
Joined: 12 May 2006 01:13

#16 Post by ghostmachine4 » 04 Nov 2009 01:40

isacmahad wrote:If you could plz run the source script on the other post and offer your assistance I would greatly appreciate it.

you can wait for avery or others since you are a batch guy. I am not. I would use the more appropriate programming language to do what you did, especially since xml is involved, i would get a real XML parser module. (or are you even doing XML parsing, i wonder) ..

So might I ask you your thoughts on powershell, and its string parsing capabilities?

powershell is just another scripting environment for you to do admin task in newer version of windows. its no different than, say using vbscript or Python, or Perl ...etc...(Except of course if you are doing something very .NET specific)
Anyway, you have to do more research on its string parsing capabilities yourself as i dont' use Powershell. Natively, vbscript is still the best for me. The other more commonly used tools that have excellent string parsing capabilities and work on multi platform, is Python and Perl.

isacmahad
Posts: 44
Joined: 29 Oct 2009 23:08

#17 Post by isacmahad » 04 Nov 2009 02:42

I am very familiar with py and a little with perl would you be able to recommend any good starting points (websites, books, etc....) for exploring perl. I have active on my sys at the moment however I very rarely use it.

ghostmachine4
Posts: 319
Joined: 12 May 2006 01:13

#18 Post by ghostmachine4 » 04 Nov 2009 02:54

isacmahad wrote:I am very familiar with py and a little with perl would you be able to recommend any good starting points (websites, books, etc....) for exploring perl. I have active on my sys at the moment however I very rarely use it.

if you have installed the distribution, you can type

Code: Select all

perldoc perl 

on the command line. Or go to perldoc.perl.org directly. The perldoc is all you need to explore Perl. Its contents are excellent. Also, since you are familiar with Python, you can also do your project with it. Clean and understandable syntax is beneficial if your project is fairly large. Python's string parsing capabilities, even without regex, are also excellent.

isacmahad
Posts: 44
Joined: 29 Oct 2009 23:08

#19 Post by isacmahad » 04 Nov 2009 03:18

I'm going to have to agree with you on this. Preforming this project using batch seems rather ridiculous. So it would seem another language would be the key, however I would just prefer to stay away from c languages and keep it open to scripting, but than again the appeal of being completely portable to all windows machines would be nice, there is no need to do this for linux in my opinion bash is just fine the way it is. Its nice to see microsoft finally get their heads out of sand and create a somewhat equal to in powershell, but there is still ground work to be covered there as well. I see that perl happens to be fruitful on many environments, and perl seems to have its own variation of batch scripts to boot. Tisk I think my 5mins of thrill in attempting to work around batch is done. batch is garbage, they do need to do away with this pile of rubbish.
Thank you for shedding light on what would have become a wasted adventure and pissed away hours of learning something useless.

ghostmachine4
Posts: 319
Joined: 12 May 2006 01:13

#20 Post by ghostmachine4 » 04 Nov 2009 04:01

isacmahad wrote:however I would just prefer to stay away from c languages and keep it open to scripting

C is not needed unless you want to program low level stuffs such as drivers. C is rather out dated (although it still has its uses, but not much in today's internet environment). Nowadays, if speed is needed, for example, in Python, you can extend C for the speed portion, and still leave the easy part of programming to Python. Same with Perl.

but than again the appeal of being completely portable to all windows machines would be nice, there is no need to do this for linux in my opinion bash is just fine the way it is.

everybody's definition of "portable" is different. To me, when i write a Python or Perl script in Windows, I can port my code to another platform, such as linux with no or minimal changes. That's portability for me.

Its nice to see microsoft finally get their heads out of sand and create a somewhat equal to in powershell,

still, it only works in M$ environment. to me, i prefer my tool to work in heterogeneous environment. but that's just me since i spend my time working with *nixes and windows...


but there is still ground work to be covered there as well. I see that perl happens to be fruitful on many environments, and perl seems to have its own variation of batch scripts to boot.

yes, so does Python. these 2 are most commonly used for system admin as well as general purpose programming. You can just be very proficient in one, and you don't have to use anything else.


Tisk I think my 5mins of thrill in attempting to work around batch is done. batch is garbage, they do need to do away with this pile of rubbish.
Thank you for shedding light on what would have become a wasted adventure and pissed away hours of learning something useless.

Batch in today's context is outdated. It doesn't provide libraries and it lacks programming features that makes programming easy. if you explore further, the things we do today are not like zion years ago. Today's programming environment requires us to (some examples)
1) script getting a web page and parsing it to get data,
2) do file transfer from one machine to the next
3) parse excel file and get columns and row data
4) produce a pdf from a word document.
5) find suspicious ips in a firewall log file
6) parse XML tags and get values
7) create XML files
8) etc and many more complicated tasks

as you can see, most of everyday task involve some kind of parsing, which batch serious lacks that capability. Not so with Perl, for example, modules for doing the above stuff can easily be found, coupled with excellent parsing capabilities, its a good tool to have definitely

ghostmachine4
Posts: 319
Joined: 12 May 2006 01:13

#21 Post by ghostmachine4 » 04 Nov 2009 04:06

isacmahad wrote:Preforming this project using batch seems rather ridiculous. .

I want to ask again, what exactly do you want to do. describe your specs again. I don't need you show any code. Just show input files if you have, and describe your output that you want. that's all i need.
If your project is easy, i am ok to help , but not in batch.

isacmahad
Posts: 44
Joined: 29 Oct 2009 23:08

#22 Post by isacmahad » 04 Nov 2009 16:02

The project originally started as a way to clean up batches sloppy syntax and add some more support for today's demanding market without the need of to many extended tools, however doing this in batch alone is not practical. I'm thinking now of building the project around other languages and including them as extended support.
Some examples of structures I wish to support.

"01") Port system utilities to other operating system environments (e.g., convert script from Perl4 to Perl5, convert script from Unix to NT).
"02") Configure/create templates for user interfaces and user environment
"03") Write local environment documentation to support users
"04") Evaluate potential problems, liabilities, and costs of potential or actual security attacks (i.e., risk analysis).
"05") Manage cryptographic facilities to protect sensitive information in network applications (e.g., PGP encryption in electronic mail).
"06") Perform automated housekeeping and clean-up activities (e.g., remove files, log rotation, archive, delete old users).
"07") Develop or enhance software tools to automate tasks (e.g., write scripts).
"08") Develop/maintain records and technical documentation (e.g., software version numbers, user logins, system architecture, licenses, descriptions).
"09") Develop/maintain daily operation logs to track problems and to establish an audit trail to debug and isolate potential problems (e.g., track mean time between failures and uptimes).
"10") Maintain data in work request and tracking systems (e.g., Remedy, clarify, Tkrep, MHQ).
"11") Support for php, perl, python, jquery, ruby (eg., Parsing xml)
"12") Extended script support for cmds batch script context

ghostmachine4
Posts: 319
Joined: 12 May 2006 01:13

#23 Post by ghostmachine4 » 04 Nov 2009 17:35

from your description, it seem to me you are trying to create another language.

isacmahad
Posts: 44
Joined: 29 Oct 2009 23:08

#24 Post by isacmahad » 04 Nov 2009 19:12

In some ways yes, more or a less an extended scripting language to an already existing language that is in need of some help, (batch), however with mounds and mounds of languages already out there I would prefer not to add another pile to the garbage collection, so I am researching, researching, RESEARCHING before I finalize on a base. The challenge I had bestowed upon myself as I described in an earlier post was to do this using batch and just to change around the syntax a bit and make it more user friendly (a joke to say the least). I also stated that I was a c++ programmer so I know my way around libraries and am quite familiar with the building blocks and requirements it takes to accomplish such. An extending scripting language is what we will call this project. One with customizable user defined syntax. You say batch has terrible string parsing capabilities, and I do not disagree, and with most languages they usually start off by creating a few functions and expanding from there. Now I am quite aware that utilities like gawk and sysinternals exist. I'm not looking to rewrite the wheel, just to expand on it. So say you have a script and in order for this script to run it either A. requires an external exe to execute such as perl python or autoit, or B. to be compiled into standalones allowing them to run anywhere the .net framework is used. Now imagine that in these languages exist your standard keywords, functions, variables bit operators, static methods all defined by the language its self. Now what if you could change the source in short like creating a whole lot of variables except these variables would be global through out the entire system so you would actually be changing the source to reflect what you want it to say. So maybe I have a few commands that say things like PrintToScreen but when the consumer uses the language they don't like PrintToScreen they want PrintToConsole because it is more familiar to there needs. Or perhaps in batch having the ugly > %% ~ - taken out and replaced with more understandable context completely defined by the programmer. This is one thing I very much enjoy in c++ is the ability to define your own syntax, problem there is everyone writes in c++ and it is not open to change once things are said and done.

isacmahad
Posts: 44
Joined: 29 Oct 2009 23:08

#25 Post by isacmahad » 04 Nov 2009 19:39

What are thoughts on ruby, ruby on rails, gems etc?

ghostmachine4
Posts: 319
Joined: 12 May 2006 01:13

#26 Post by ghostmachine4 » 04 Nov 2009 20:14

isacmahad wrote:What are thoughts on ruby, ruby on rails, gems etc?

ruby is a "better Perl" to ruby users, but that's subjective. I personally think they are all the same. they all can do the same task, the only difference is whether they enable the programmer to do it easily or not.

ruby on rails is just a web application framework. Much like Python's django or Perl Catalyst...

isacmahad
Posts: 44
Joined: 29 Oct 2009 23:08

#27 Post by isacmahad » 04 Nov 2009 20:20

I guess my next question would have to be.
Is my idea completely absurd or is it worth taking a go at?

isacmahad
Posts: 44
Joined: 29 Oct 2009 23:08

#28 Post by isacmahad » 04 Nov 2009 20:27

....also if you could (going back a bit to the open discussion about str manipulation) take a look at this and give your thoughts. I know this is a dos forum however you and I seem to be the only ones discussing in this thread so I hope this wont be frowned upon by the admins. If so please remove this post. Thank You

Code: Select all

# >@ Splitat (protect)          :: Don't Split (protect)
# <> Splitaround (protect)      ;;r Remove
# ;;> Space Split               ;;a Split Letters
#;;d Split Numbers              ;;e No Empty
def MultiSplit(string ,action ,sp = ['<>','>@','::','~~','>?']):
    loop , start = 0 ,0
    word = {}
    noempty = False
    # sp[Splitaround ,Splitat ,Don't Split ,Mtag , Potect]

    for A in action:
        if sp[0] in A:
            word[sp[0]+sp[4]*loop+sp[0]] = A[len(sp[0]):]
            string = string.replace(A[len(sp[0]):],sp[3]+sp[0]+sp[4]*loop+sp[0]+sp[3])
        elif sp[1] in A:
            word[sp[1]+sp[4]*loop+sp[1]] = A[len(sp[1]):]
            string = string.replace(A[len(sp[1]):],sp[3]+sp[1]+sp[4]*loop+sp[1])
        elif sp[2] in A:
            word[sp[2]+sp[4]*loop+sp[2]] = A[len(sp[2]):]
            string = string.replace(A[len(sp[2]):],sp[2]+sp[4]*loop+sp[2])
        elif ';;r' in A:
            for r in A[3:].split(','):
                string = string.replace(r,'')
        elif ';;>' in A:
            num = A[3:].split(',')
            dstr = ''
            if num[0] == '0':
                start = 0
                for n in xrange(int(num[1]),len(string),int(num[1])):
                    dstr = dstr + string[start:n] + sp[3]
                    start = n
                string = dstr + string[start:]
            elif str(len(string)) == num[0]:
                start,rd = 0,0
                for n in num[1:]:
                    rd = rd + int(n)
                    dstr = dstr + string[start:rd] + sp[3]
                    start = rd
                string = dstr + string[start:]
        elif ';;a' in A:
            start, loop, dstr, = 0,0,''
            code = not string[0].isalpha()
            for x in string:
                if x.isalpha() == code:
                    end = loop
                    dstr += string[start:end] + sp[3]
                    start = end
                    code = not code
                loop += 1
            string = dstr + string[start:]
        elif ';;d' in A:
            start, loop, dstr, = 0,0,''
            code = not string[0].isdigit()
            for x in string:
                if x.isdigit() == code:
                    end = loop
                    dstr += string[start:end] + sp[3]
                    start = end
                    code = not code
                loop += 1
            string = dstr + string[start:]
        elif ';;e' in A:
            noempty = True
        else:
            string = string.replace(A,sp[3])
        loop += 1

    for key in word.keys():
        string = string.replace(key,word[key])

    if noempty:
        string = string.split(sp[3])
        dstr = []
        for s in string:
            if len(s) > 0:
                dstr.append(s)
        return dstr
    return string.split(sp[3])
   
if __name__ == '__main__':
    # action is a list that process from first to last.
    x = 'apopillpeepopsnowpopapple'
    print MultiSplit(x,['>@po','::pp','>@pill','p'])
    x = 'popcappoptartpopcar'
    print MultiSplit(x,['pop',';;e'])
    print MultiSplit(x,['>@pop'])
    x = '23 + 45 / 2 - 1 * 1.2'
    print MultiSplit(x,[';;r ','<>+','<>-','<>/','<>*'])
    x='15551115555'
    print MultiSplit(x,[';;>11,1,3,3',';;>10,3,3'])
    x='1112225555'
    print MultiSplit(x,[';;>11,1,3,3',';;>10,3,3'])
    x='catdogtoypupthehatit'
    print MultiSplit(x,[';;>0,3'])
    x='we#123are2be45for$you'
    print MultiSplit(x,[';;a',';;d',';;e'])
    x = '1234do1234u1234now'
    print MultiSplit(x,[';;r1,2,3','4',';;e'])

ghostmachine4
Posts: 319
Joined: 12 May 2006 01:13

#29 Post by ghostmachine4 » 04 Nov 2009 20:46

isacmahad wrote:I guess my next question would have to be.
Is my idea completely absurd or is it worth taking a go at?

Its not really absurd because who doesn't want to improve things that's broken?
The question is, if it were me, i would go straight to the source and change it. Like the saying goes, tackle the problem at its root. If not , we are just kidding ourselves. That's why now M$ gives you things like vbscript or powershell to top up cmd.exe's incapabilities.

As for you rPython script, if the function is useful to you, you should test it thoroughly and document it. what each option does, For further opinions, please post to comp.lang.python.

isacmahad
Posts: 44
Joined: 29 Oct 2009 23:08

#30 Post by isacmahad » 05 Nov 2009 15:40

I was wondering about some good external tools for grabbing the http https page source through the command line, if this is possible, and if you could make some recommendations.

Post Reply