Comments (2)
A work around for those who encounter this problem.
FOR /f tokens^=1delims^=^" %%i IN ("%1") do ( set fullpath=%%~i set drive=%%~di set filepath=%%~pi set name=%%~ni set fileext=%%~xi )
This will explode %1 arg in usefull component and remove the double insertion. Not clean but functionnal.
Use this just before using %1 and change %1 to %fullpath%, other component are there to manipulate the provided file name.
from bat2exe.
ran into this today. @reno3131's solution did not work for me:
- the different
set
s needed to be on different lines, otherwise it setsfullpath
to the rest of the line - it seems to assume the argument is quoted and uses that as a delimiter. so this solution does not work for unquoted arguments.
i was trying to invoke the converted exe as a default program to open certain type of files. apparently when Windows passes the filepath to the program it doesn't quote the filepath.
never worked with batch before, so my solution is probably stupid and ugly. but I thought i'd share anyway. i simply took half of the argument and tested if the argument is the same string repeated twice:
Rem Hack for bat2exe.
Rem ==========
Rem Bat2exe has a bug where it duplicates the argument. See https://github.com/islamadel/bat2exe/issues/9.
Rem For example, running
Rem script.exe Hello
Rem would be equivalent as running
Rem script.bat HelloHello
Rem To handle this, we take half of the argument and see if the argument is the
Rem half repeated twice. If that is the case, set "arg" to the half.
setlocal EnableDelayedExpansion
set arg=%1
call :strlen len arg
set /A len=%len%/2
call set arg_half=%%arg:~0,%len%%%
if !arg! == !arg_half!!arg_half! (set arg=%arg_half%)
Rem Fucntion that returns length of a string. See stackoverflow.com/a/5841187.
:strlen <resultVar> <stringVar>
(
setlocal EnableDelayedExpansion
(set^ tmp=!%~2!)
if defined tmp (
set "len=1"
for %%P in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do (
if "!tmp:~%%P,1!" NEQ "" (
set /a "len+=%%P"
set "tmp=!tmp:~%%P!"
)
)
) ELSE (
set len=0
)
)
(
endlocal
set "%~1=%len%"
exit /b
)
Use arg
henceforth.
from bat2exe.
Related Issues (9)
- Did Not Accurately Convert .bat to .exe HOT 2
- current directory
- Error can't find .bat is resolved by not using special characters like ( or ) in the folders name
- Error when running the .exe file created by bat2exe HOT 5
- Virus warning when downloading HOT 2
- 7zSD.sfx HOT 1
- Arguments HOT 2
- Can't use to make a .bat->.exe to run a .exe within same terminal/prompt window HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bat2exe.