|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
 『楼 主』:
[讨论]批处理脚本和程序设计语言的比较
使用 LLM 解释/回答一下
学习批处理已经有一段时间了,感觉批处理脚本和很多程序设计语言有很多地方是相通的,特别是在算法上更是相通。把其它程序设计语言的算法拿到批处理里面来同样适用,当然只是算法上是类同的道理,实际语句就不一样了。 ^_^
就我个人感觉,批处理脚本和其它程序设计语言有以下方面是相通的(和大家熟悉的C语言比较吧):
--------------------------------------- 变量的赋值
批处理里面可以用set命令来赋值,而C语言里面是类似"int a=1"这样来赋值的。
判断语句
批处理里面可以用if来判断,同样,C语言里面也是用if。
循环语句
批处理脚本里面可以用for来实现循环功能(当然,要在批处理里实现循环还有其它的很多方法~),这和C里面的for大同小异。
输入语句
C语言里面可以用"Scanf()"函数来实现输入操作,而在批处理里面就可以用"set /p a="来替代了。
输出语句
C语言里面可以用"Printf()"函数来实现输出操作,在批处理里面就可以用一个简单的"echo"语句来完成了。
函数
C语言里面可以调用函数来直接完成一些任务,我觉得批处理里面的"call"和"goto"命令结合上标签之后,就相当于是一个"函数"了。可以先用批处理把要实现的功能写好,然后把代码保存在.bat文件或者.cmd文件里面,或者直接放在要调用它的批处理脚本里面,然后用"call"或者"goto"调用它就可以了,这就不相当于一个函数了么? =_=
参数
C语言里面有参数,批处理文件和命令同样可以接受各种参数。
算法
很多算法都是相通的。
---------------------------------------
以上只是个人愚见,由于经验以及各方面的原因,难免会有疏漏和错误的地方,欢迎大家来讨论、批评、指正。如果还有其它方面的相通点我没有提到的,大家可以发帖来讨论,我会完善原文的内容的。
可能有的朋友会认为,一个是脚本,一个是程序设计语言,两者没法比较,而我写这个文章的目的就是使大家对批处理有一个更新的认识,仅此而已。
Last edited by lxmxn on 2006-11-16 at 03:34 AM ]
I have been learning batch processing for some time. I feel that batch processing scripts have many things in common with many programming languages, especially in algorithms. The algorithms from other programming languages can also be applied to batch processing. Of course, it is only the similarity in algorithms, and the actual statements are different. ^_^
In my personal opinion, batch processing scripts have the following aspects in common with other programming languages (compared with the familiar C language):
--------------------------------------- Variable assignment
In batch processing, you can use the set command to assign values, while in C language, it is assigned like "int a=1".
Judgment statement
In batch processing, you can use if to judge, and similarly, in C language, you also use if.
Loop statement
In batch processing scripts, you can use for to implement the loop function (of course, there are many other methods to implement loops in batch processing~), which is similar to the for in C.
Input statement
In C language, you can use the "Scanf()" function to implement input operations, while in batch processing, you can use "set /p a=" instead.
Output statement
In C language, you can use the "Printf()" function to implement output operations, and in batch processing, you can use a simple "echo" statement to complete it.
Function
In C language, you can call functions to directly complete some tasks. I think that the combination of the "call" and "goto" commands in batch processing with labels is equivalent to a "function". You can first write the functions to be implemented in batch processing, then save the code in a.bat file or.cmd file, or directly put it in the batch processing script that calls it, and then call it with "call" or "goto", which is not equivalent to a function? =_=
Parameter
In C language, there are parameters, and batch processing files and commands can also accept various parameters.
Algorithm
Many algorithms are similar.
---------------------------------------
The above are just my humble opinions. Due to experience and various reasons, there are inevitable omissions and errors. Everyone is welcome to discuss, criticize, and correct. If there are other common points that I haven't mentioned, everyone can post to discuss, and I will improve the content of the original text.
Maybe some friends think that one is a script and the other is a programming language, and the two cannot be compared. And the purpose of me writing this article is to make everyone have a new understanding of batch processing, that's all.
Last edited by lxmxn on 2006-11-16 at 03:34 AM ]
|
|
2006-11-16 03:33 |
|
|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
函数
C语言里面可以调用函数来直接完成一些任务,我觉得批处理里面的"call"和"goto"命令结合上标签之后,就相当于是一个"函数"了。可以先用批处理把要实现的功能写好,然后把代码保存在.bat文件或者.cmd文件里面,或者直接放在要调用它的批处理脚本里面,然后用"call"或者"goto"调用它就可以了,这就不相当于一个函数了么? =_=
个人认为这只是一个 sub,即过程。 函数要返回值的。而 Goto 只能通过一个公共变量来交换值
Function
In C language, you can call functions to directly complete some tasks. I think that the combination of the "call" and "goto" commands in batch processing with labels is equivalent to a "function". You can first write the functions to be implemented with batch processing, then save the code in a .bat file or .cmd file, or directly put it in the batch script that needs to call it, and then call it with "call" or "goto", isn't this equivalent to a function? =_=
Personally, I think this is just a sub, that is, a procedure. A function needs to return a value. And Goto can only exchange values through a public variable
|

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>" |
|
2006-11-16 03:39 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
个人认为这只是一个 sub,即过程。 函数要返回值的。而 Goto 只能通过一个公共变量来交换值
恩,还是有很多区别的,不过大体功能就是那样,都可以被调用来实现一些功能。
Personally, I think this is just a sub, that is, a procedure. A function returns a value. And Goto can only exchange values through a public variable
Well, there are still many differences, but the general functions are like that, both can be called to implement some functions.
|
|
2006-11-16 03:48 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
都大同小易,只不过命令不同
They are all similar, just different commands
|
|
2006-11-16 04:11 |
|
|
anakin
新手上路

积分 1
发帖 4
注册 2006-10-12
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
不错.....都大同小异
Not bad.....all pretty much the same
|
|
2006-11-20 04:40 |
|
|
kxows
初级用户
 
积分 31
发帖 11
注册 2006-11-7
状态 离线
|
|
2006-11-20 05:53 |
|
|
hxuan999
中级用户
   DOS之日
积分 337
发帖 161
注册 2006-11-4
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
不错呀,应该写出代码来对比一下.
Not bad. Should write code to compare.
|

for /f %%h in (`echo hxuan`) do for /f %%x in (`echo hxuan`) do if %%h==%%x nul |
|
2006-11-23 07:38 |
|
|
yunlin
新手上路

积分 5
发帖 7
注册 2006-11-25
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
看不懂
第一次来
新手来着
顶你了 老公
Don't understand
First time here
Newcomer
Got your back, honey
|
|
2006-11-25 15:48 |
|
|
kaidi
新手上路

积分 16
发帖 8
注册 2006-11-4
状态 离线
|
|
2007-1-27 11:02 |
|
|
ccwan
金牌会员
     
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
  『第 10 楼』:
使用 LLM 解释/回答一下
我比较赞同楼主的意见,计算机语言是有很多相通之处的。
对于7楼要求写出代码作为例子,我这里分别给出C语言和批处理的一个例子,很能说明问题。
题目:有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?
C语言代码:
#include "stdio.h"
#include "conio.h"
main()
{
int i,j,k;
printf("\n");
for(i=1;i<5;i++) /*以下为三重循环*/
for(j=1;j<5;j++)
for (k=1;k<5;k++)
{
if (i!=k&&i!=j&&j!=k) /*确保i、j、k三位互不相同*/
printf("%d,%d,%d\n",i,j,k);
}
}
批处理代码:
@echo off
cd.>test.txt
for /l %%i in (1 1 4) do (
for /l %%j in (1 1 4) do (
for /l %%k in (1 1 4) do (
if not "%%i"=="%%j" if not "%%j"=="%%k" if not "%%i"=="%%k" echo %%i%%j%%k>>test.txt&set/a num+=1
)
)
)
echo 共能组成%num%个互不相同且无重复数字的三位数>>test.txt
start notepad.exe test.txt
上例不难看出,解题思路一样,甚至代码都很相似 。
I quite agree with the LZ's opinion that there are many commonalities among computer languages.
For the request from the 7th floor to write code as an example, here I respectively give an example in C language and batch processing, which can well illustrate the problem.
Title: There are numbers 1, 2, 3, 4. How many three-digit numbers that are distinct from each other and have no repeated digits can be formed? And what are they?
C language code:
#include "stdio.h"
#include "conio.h"
main()
{
int i,j,k;
printf("\n");
for(i=1;i<5;i++) /*The following are three nested loops*/
for(j=1;j<5;j++)
for (k=1;k<5;k++)
{
if (i!=k&&i!=j&&j!=k) /*Ensure that the three digits i, j, k are all distinct from each other*/
printf("%d,%d,%d\n",i,j,k);
}
}
Batch processing code:
@echo off
cd.>test.txt
for /l %%i in (1 1 4) do (
for /l %%j in (1 1 4) do (
for /l %%k in (1 1 4) do (
if not "%%i"=="%%j" if not "%%j"=="%%k" if not "%%i"=="%%k" echo %%i%%j%%k>>test.txt&set/a num+=1
)
)
)
echo A total of %num% three-digit numbers that are distinct from each other and have no repeated digits can be formed>>test.txt
start notepad.exe test.txt
It is not difficult to see from the above example that the problem-solving ideas are the same, and even the codes are very similar.
|

三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2007-1-27 21:23 |
|
|
TLang
初级用户
  Alpha
积分 46
发帖 21
注册 2007-1-27
状态 离线
|
『第 11 楼』:
批处理能运算么?!!
使用 LLM 解释/回答一下
批处理能运算么?!!
Can batch processing be used for operations?!
|

Impossible's Nothing! |
|
2007-1-27 22:48 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
Originally posted by TLang at 2007-1-27 09:48:
批处理能运算么?!!
set /a
当然,有一定的限制
Originally posted by TLang at 2007-1-27 09:48:
Can batch processing perform calculations?!
set /a
Of course, with certain limitations
|
|
2007-1-27 22:52 |
|
|
TLang
初级用户
  Alpha
积分 46
发帖 21
注册 2007-1-27
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
Originally posted by zh159 at 2007-1-27 09:52:
set /a
当然,有一定的限制
是,只是基本的运算
IF语句也比较简易
……
总之个人感觉WinXPSP2时代,虽然对命令行命令以及批处理命令有了很大扩展,但是都还是比较简易,基础的~~
Originally posted by zh159 at 2007-1-27 09:52:
set /a
Of course, there are certain limitations
Yes, just basic operations
The IF statement is also relatively simple
......
In short, personally, I feel that in the WinXP SP2 era, although there have been great expansions to command-line commands and batch commands, they are still relatively simple and basic.
|

Impossible's Nothing! |
|
2007-1-27 23:27 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
Originally posted by TLang at 2007-1-27 10:27:
是,只是基本的运算
IF语句也比较简易
……
总之个人感觉WinXPSP2时代,虽然对命令行命令以及批处理命令有了很大扩展,但是都还是比较简 ...
呵呵,毕竟它是个脚本嘛,哪有高级语言那么多的函数可供你直接用呢?
Originally posted by TLang at 2007-1-27 10:27:
Yes, just basic operations
The IF statement is also relatively simple
......
In short, personally, I feel that in the WinXP SP2 era, although there were great expansions to command-line commands and batch processing commands, they were still relatively simple...
Hehe, after all, it's a script. How can it have as many functions as high-level languages for you to use directly?
|
|
2007-1-28 11:55 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
大炮、导弹、冲锋枪……在战争中缺了谁都不行,它们各有所长,它们将实用在战争中的每一个需要发挥它们特长的地方~:)
对于枪,我一辈子也可能摸不到或是用不到(当然也买不到,哈哈)。但是它对某些人来说失去它就等于失去了宝贵的生命~:)
把最适合或是适合用在某些环境的工具或是脚本或是某种语言,并尽可能让它们物尽所长,就是艺术~:)
(个人瞎说,权当玩笑,虽然还是梦想着能有一把枪~:)
Cannons, missiles, submachine guns... In war, none can be missing. Each has its own strengths and will be put to use in every place in war where its strengths need to be exerted~:)
For guns, I might never touch or use one in my whole life (and of course can't buy one, haha). But for some people, losing it means losing precious lives~:)
Using the most suitable or suitable tools or scripts or a certain language in certain environments and making them give full play to their functions as much as possible is art~:)
(Personal rambling, just for fun, although still dreaming of having a gun~:)
|

Redtek,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2007-1-29 01:04 |
|