Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: %1 is carried over to other batch file  (Read 8860 times)

0 Members and 1 Guest are viewing this topic.

Helpmeh

    Topic Starter


    Guru

  • Roar.
  • Thanked: 123
    • Yes
    • Yes
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 8
%1 is carried over to other batch file
« on: February 21, 2010, 07:58:20 AM »
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.
Where's MagicSpeed?
Quote from: 'matt'
He's playing a game called IRL. Great graphics, *censored* gameplay.

Salmon Trout

  • Guest
Re: %1 is carried over to other batch file
« Reply #1 on: February 21, 2010, 08:13:07 AM »
Could you possibly provide the code of the batch files?

Helpmeh

    Topic Starter


    Guru

  • Roar.
  • Thanked: 123
    • Yes
    • Yes
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 8
Re: %1 is carried over to other batch file
« Reply #2 on: February 21, 2010, 08:18:41 AM »
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
Where's MagicSpeed?
Quote from: 'matt'
He's playing a game called IRL. Great graphics, *censored* gameplay.

Salmon Trout

  • Guest
Re: %1 is carried over to other batch file
« Reply #3 on: February 21, 2010, 08:22:10 AM »
I'd still like to see the first batch file.

Helpmeh

    Topic Starter


    Guru

  • Roar.
  • Thanked: 123
    • Yes
    • Yes
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 8
Re: %1 is carried over to other batch file
« Reply #4 on: February 21, 2010, 08:24:35 AM »
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
Where's MagicSpeed?
Quote from: 'matt'
He's playing a game called IRL. Great graphics, *censored* gameplay.

Salmon Trout

  • Guest
Re: %1 is carried over to other batch file
« Reply #5 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?

Helpmeh

    Topic Starter


    Guru

  • Roar.
  • Thanked: 123
    • Yes
    • Yes
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 8
Re: %1 is carried over to other batch file
« Reply #6 on: February 21, 2010, 08:33:59 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.
Where's MagicSpeed?
Quote from: 'matt'
He's playing a game called IRL. Great graphics, *censored* gameplay.

Salmon Trout

  • Guest
Re: %1 is carried over to other batch file
« Reply #7 on: February 21, 2010, 09:03:45 AM »
Why don't you just do this?

set pth="%~dp1"


Helpmeh

    Topic Starter


    Guru

  • Roar.
  • Thanked: 123
    • Yes
    • Yes
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 8
Re: %1 is carried over to other batch file
« Reply #8 on: February 21, 2010, 09:06:06 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?
Where's MagicSpeed?
Quote from: 'matt'
He's playing a game called IRL. Great graphics, *censored* gameplay.

Salmon Trout

  • Guest
Re: %1 is carried over to other batch file
« Reply #9 on: February 21, 2010, 09:17:23 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

Helpmeh

    Topic Starter


    Guru

  • Roar.
  • Thanked: 123
    • Yes
    • Yes
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 8
Re: %1 is carried over to other batch file
« Reply #10 on: February 21, 2010, 09:20:35 AM »
'controller.bat" ' is not recognized as a ... you know the rest.
Where's MagicSpeed?
Quote from: 'matt'
He's playing a game called IRL. Great graphics, *censored* gameplay.

Salmon Trout

  • Guest
Re: %1 is carried over to other batch file
« Reply #11 on: February 21, 2010, 09:24:19 AM »
'controller.bat" ' is not recognized as a ... you know the rest.

is controller.bat in the same folder?

Helpmeh

    Topic Starter


    Guru

  • Roar.
  • Thanked: 123
    • Yes
    • Yes
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 8
Re: %1 is carried over to other batch file
« Reply #12 on: February 21, 2010, 09:25:17 AM »
Yes. The first file is called random_music.bat and the second is controller.bat . They are both in the same folder.
Where's MagicSpeed?
Quote from: 'matt'
He's playing a game called IRL. Great graphics, *censored* gameplay.

Salmon Trout

  • Guest
Re: %1 is carried over to other batch file
« Reply #13 on: February 21, 2010, 09:30:00 AM »
doesn't

start "" "controller.bat"

work?

Helpmeh

    Topic Starter


    Guru

  • Roar.
  • Thanked: 123
    • Yes
    • Yes
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 8
Re: %1 is carried over to other batch file
« Reply #14 on: February 21, 2010, 09:38:42 AM »
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.
Where's MagicSpeed?
Quote from: 'matt'
He's playing a game called IRL. Great graphics, *censored* gameplay.