1.

Solve : %1 is carried over to other batch file?

Answer»

For some reason, when I run one batch file, with a path as %1, for some reason when the second batch file is run by:
start cmd.exe /k "%cd%\controller.bat"

controller.bat gives a 'T:\Documents' (the beginning of the path from %1 in the original batch file) is not recognized as an internal or external command, operable program or batch file.

I really don't know exactly why %1 is carrying through, when the second batch file is in a separate instance of the command prompt, but I need to prevent the error. Could you POSSIBLY provide the code of the batch files?
Well in the first batch file, the second batch file get's started on the first line (after echo off), so I don't think the problem lies there, but here is the code for the second batch file. BTW, it runs normally if %1 doesn't exist.

Code: [Select]echo off
mode con cols=22 lines=2
title CONTROLLER
echo Type in EXIT to exit.
pause > nul
cls
echo Press ENTER to skip.
pause > nul
:looper
cls
set input=skip
set /p input=
if /i not "%input%"=="exit" (tskill mplayer2) else (del music.files & tskill mplayer2 & tskill cmd)
goto looper
I'd still like to see the first batch file.
Here you go!
Code: [Select]echo off
start cmd.exe /k "%cd%\controller.bat"
echo %1
for /f "tokens=*" %%A in ("%1") do set pth=%%~dpA
setlocal enabledelayedexpansion
if exist music.file* del music.file*
dir /b  "%pth%\*.mp3" > music.files.temp
set counter=1
for /f "delims=" %%a in (music.files.temp) do (
echo !counter! %%a >> music.files
set /a counter+=1
)
del music.files.temp
set lastsong=
:loop
set /a mus=%random%%%counter%
for /f "tokens=1*" %%b in (music.files) do (
if %%b==!mus! if "%%c"=="!lastsong!" goto loop
if %%b==!mus! start /min /wait "" "C:\Program Files\Windows Media Player\mplayer2.exe" /play /close "!pth!\%%c" & set lastsong=%%c
)
goto loop... and finally, how do you call this first batch? From the command line? And how does the mysterious %1 parameter get created?  Is that typed after the batch name?
Quote from: SALMON Trout on February 21, 2010, 08:27:22 AM

... and finally, how do you call this first batch? From the command line? And how does the mysterious %1 parameter get created?  Is that typed after the batch name?

GUI, drag a music file onto the first batch file.Why don't you just do this?

set pth="%~dp1"

Quote from: Salmon Trout on February 21, 2010, 09:03:45 AM
Why don't you just do this?

set pth="%~dp1"


I did that at one point in time...I just can't quite remember why I changed it...anyway, did you figure out why controller.bat is crashing? Quote from: Helpmeh on February 21, 2010, 09:06:06 AM
I did that at one point in time...I just can't quite remember why I changed it...anyway, did you figure out why controller.bat is crashing?

Not yet. But I wonder why you are doing this

Code: [Select]start cmd.exe /k "%cd%\controller.bat"
specifically why you are using %cd%\ ? (%cd% is the current directory and if controller.bat is in the current directory you can use just its name)

Try

Code: [Select]start "" "cmd /k controller.bat"
Make the alterations I have suggested & report back
'controller.bat" ' is not recognized as a ... you know the rest. Quote from: Helpmeh on February 21, 2010, 09:20:35 AM
'controller.bat" ' is not recognized as a ... you know the rest.

is controller.bat in the same folder?
Yes. The first file is called random_music.bat and the second is controller.bat . They are both in the same folder.doesn't

start "" "controller.bat"

WORK?
This time, instead of getting a cmd.exe error message, I get the

"Windows can not find 'controller.bat'. Make sure you typed the name correctly, and then try again. To search for a file, click the start button, and then click search."

I changed it to "%cd%\controller.bat" and it still can't find it.
I copied controller.bat and renamed the new VERSION 123.bat and it still can't find it.


Discussion

No Comment Found