中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-12 16:00
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS批处理 & 脚本技术(批处理室) » [Problem] Let the batch processing determine by itself whether it is run by double - clicking
Printable Version  3,045 / 20
Floor1 pusofalse Posted 2008-11-12 18:35
银牌会员 Posts 646 Credits 1,604
Title: Understand the batch processing operation mechanism.

Bonus rules:
Novel idea 8 points
No temporary files 3 points
Concise code 3 points
Perfect code 15 points

Title content:
Let the batch processing judge by itself whether it is double-clicked to run or manually input and run in CMD.
Just like tasklist.exe, net.exe, ping.exe, when we double-click these files, they will flash by and we can't see the help information of these commands. Only when we manually input in CMD can we see. Now the question is to write a batch file. When we double-click to run (without any parameters), display "Double-click to run" and pause. If it is manually input and run in CMD (also without any parameters), display "Run manually input in CMD" and then do not pause, directly return to the command prompt.
Floor2 lxmxn Posted 2008-11-12 19:49
版主 Posts 4,938 Credits 11,386

Is this okay?
Floor3 pusofalse Posted 2008-11-12 20:13
银牌会员 Posts 646 Credits 1,604
Floor4 BC Posted 2008-11-12 20:29
中级用户 Posts 175 Credits 338
Floor5 slore Posted 2008-11-12 22:39
铂金会员 Posts 2,478 Credits 5,212
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Administrator>"C:\Documents and Settings\Administrator
\Desktop\123.bat"
Double-click to run
CommandLine
"C:\WINDOWS\system32\cmd.exe"
cmd /c ""C:\Documents and Settings\Administrator\Desktop\123.bat" "
cmd /c ""C:\Documents and Settings\Administrator\Desktop\123.bat" "
"C:\WINDOWS\system32\cmd.exe"

Press any key to continue. . .
Floor6 lxmxn Posted 2008-11-13 11:00
版主 Posts 4,938 Credits 11,386
Hehe, special circumstances naturally didn't consider so much.
Floor7 tireless Posted 2008-12-06 01:01
银牌会员 Posts 1,122 Credits 2,025
```
@echo off
if "%~1"=="" (
if "%~0"=="%~nx0" (
echo Run manually in CMD
) else (
echo Run by double-clicking & pause
)
)
```

Utilization: Double-clicking will display the full path of the batch file itself, while in the command prompt window only the file name is displayed.
(Of course, if the full path is entered in the command prompt window, it will be misjudged)
Floor8 523066680 Posted 2009-10-10 19:46
银牌会员 Posts 1,133 Credits 2,362
It will become a classic! Although I'm not new here, I still post to boost it.
Floor9 netbenton Posted 2009-10-10 21:56
银牌会员 Posts 752 Credits 1,916 From 广西
Unless double quotes are included when entering at the command line, and also pay attention to sometimes uppercase and sometimes lowercase, otherwise it should not be misjudged, right!

Floor10 plp626 Posted 2009-10-11 18:19
银牌会员 Posts 1,020 Credits 2,278
re: netbenton

Brother's code still lacks consideration. There is a special case for the system variable cd that the last character in the root directory does not have "\". It seems that this point is still ignored by many people.

In fact, judging by the cmdcmdline variable is more orthodox.
Floor11 netbenton Posted 2009-10-11 19:42
银牌会员 Posts 752 Credits 1,916 From 广西
What's a little more?
Floor12 plp626 Posted 2009-10-12 17:26
银牌会员 Posts 1,020 Credits 2,278
I can't answer this question. You can provide other topics and I will try my best to help you.
Floor13 523066680 Posted 2009-10-12 17:42
银牌会员 Posts 1,133 Credits 2,362
Calling in cmd...


C:\Documents and Settings\liubo\Desktop>call a.bat
There should not be /c at this time.

C:\Documents and Settings\liubo\Desktop>@if ""C:\WINDO"=="cmd /c " (echo Double-click) else (echo Not double-click)

C:\Documents and Settings\liubo\Desktop>

(Warm reminder, liubo is not my name, I don't call Liu Bo... Don't make fun of me ha)

[ Last edited by 523066680 on 2009-10-12 at 17:49 ]
Floor14 plp626 Posted 2009-10-12 18:17
银牌会员 Posts 1,020 Credits 2,278
Robust be tested by everyone

Floor15 plp626 Posted 2009-10-12 18:35
银牌会员 Posts 1,020 Credits 2,278
Originally posted by pusofalse at 2008-11-12 06:35 PM:
The purpose of the question: To understand the operation mechanism of batch processing.

Bonus rules:
8 points for novel ideas
3 points for no temporary files
3 points for concise code
15 points for perfect code

Question content:
Let the batch processing determine by itself whether it is...


I don't know if this is the meaning

http://bbs.bathome.cn/viewthread.php?tid=4725
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023