China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-29 10:55
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Discussion] Comparison between Batch Scripts and Programming Languages View 5,941 Replies 26
Original Poster Posted 2006-11-16 03:33 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline

  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 ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
redtek +3 2006-11-16 03:35
Floor 2 Posted 2006-11-16 03:39 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline

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'>"
Floor 3 Posted 2006-11-16 03:48 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
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.
Floor 4 Posted 2006-11-16 04:11 ·  中国 甘肃 甘南藏族自治州 合作市 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
They are all similar, just different commands
Floor 5 Posted 2006-11-20 04:40 ·  中国 山东 济南 联通
新手上路
Credits 1
Posts 4
Joined 2006-10-12 01:49
19-year member
UID 65389
Status Offline
Not bad.....all pretty much the same
Floor 6 Posted 2006-11-20 05:53 ·  中国 安徽 池州 电信
初级用户
Credits 31
Posts 11
Joined 2006-11-07 08:16
19-year member
UID 69884
Gender Male
Status Offline
Floor 7 Posted 2006-11-23 07:38
中级用户
★★
DOS之日
Credits 337
Posts 161
Joined 2006-11-04 05:27
19-year member
UID 69523
Gender Male
Status Offline
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
Floor 8 Posted 2006-11-25 15:48 ·  中国 浙江 台州 天台县 电信
新手上路
Credits 5
Posts 7
Joined 2006-11-25 14:29
19-year member
UID 71705
Gender Female
Status Offline
Don't understand
First time here
Newcomer
Got your back, honey
Floor 9 Posted 2007-01-27 11:02 ·  中国 天津 河西区 联通
新手上路
Credits 16
Posts 8
Joined 2006-11-04 08:09
19-year member
UID 69534
Gender Male
Status Offline
Study study again and again
Floor 10 Posted 2007-01-27 21:23 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
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.
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
redtek +9 2007-01-27 21:27
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 11 Posted 2007-01-27 22:48 ·  中国 辽宁 大连 联通
初级用户
Alpha
Credits 46
Posts 21
Joined 2007-01-27 02:21
19-year member
UID 77790
Gender Male
Status Offline
Can batch processing be used for operations?!
Impossible's Nothing!
Floor 12 Posted 2007-01-27 22:52 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Originally posted by TLang at 2007-1-27 09:48:
Can batch processing perform calculations?!

set /a

Of course, with certain limitations
Floor 13 Posted 2007-01-27 23:27 ·  中国 辽宁 大连 联通
初级用户
Alpha
Credits 46
Posts 21
Joined 2007-01-27 02:21
19-year member
UID 77790
Gender Male
Status Offline
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!
Floor 14 Posted 2007-01-28 11:55 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
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?
Floor 15 Posted 2007-01-29 01:04 ·  中国 北京 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
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,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Forum Jump: