Page 1 of 1
Is it possible to add another command, same line as CALL :
Posted: 05 Jul 2012 19:32
by MKANET
In the below call command, is there anyway to add a completely different command on the same line; or, is everything after the call label treated as respective parameters?
I am guessing there is no way. But just wanted to be certain.
Call :subroutine &echo subroutine complete
Re: Is it possible to add another command, same line as CALL
Posted: 05 Jul 2012 20:17
by foxidrive
Did you try this?
(Call :subroutine ) & echo subroutine complete
Re: Is it possible to add another command, same line as CALL
Posted: 05 Jul 2012 20:22
by Ed Dyreen
foxidrive wrote:Did you try this?
(Call :subroutine ) & echo subroutine complete
I doubt it, he didn't even tried his own code.
MKANET wrote:Call :subroutine &echo subroutine complete
Please run your code, post us your valuable conclusion/s and shed some light on us.
Thanks,

Re: Is it possible to add another command, same line as CALL
Posted: 05 Jul 2012 21:14
by MKANET
I should have probably rephrased my question. I was hoping to run a subsequent command
after it completes processing the subroutine. I've never been able to do that; but, thought maybe there is a way to do it.
Ed Dyreen wrote:foxidrive wrote:Did you try this?
(Call :subroutine ) & echo subroutine complete
I doubt it, he didn't even tried his own code.
MKANET wrote:Call :subroutine &echo subroutine complete
Please run your code, post us your valuable conclusion/s and shed some light on us.
Thanks,

Re: Is it possible to add another command, same line as CALL
Posted: 05 Jul 2012 21:28
by foxidrive
MKANET wrote:I should have probably rephrased my question. I was hoping to run a subsequent command after it completes processing the subroutine. I've never been able to do that; but, thought maybe there is a way to do it.
Have you run your code yet?
Re: Is it possible to add another command, same line as CALL
Posted: 05 Jul 2012 22:13
by MKANET
Yes, I was hoping that went without saying since I already clarified what I was trying to do (what you quoted). If it still doesn't make sense, below is an updated example.
If I have everything after the & on a separate line, %converted% is shown. Otherwise, it's still undefined..
Code: Select all
call :Converter &echo Converted value is %converted%
foxidrive wrote:MKANET wrote:I should have probably rephrased my question. I was hoping to run a subsequent command after it completes processing the subroutine. I've never been able to do that; but, thought maybe there is a way to do it.
Have you run your code yet?
Re: Is it possible to add another command, same line as CALL
Posted: 05 Jul 2012 22:41
by Ed Dyreen
MKANET wrote:Yes, I was hoping that went without saying since I already clarified what I was trying to do (what you quoted).
No, I disagree, the previous exemplary code didn't exhibit any problem.
MKANET wrote:Call :subroutine &echo subroutine complete
But the new code you now present us with ( which is totally different ) does.
MKANET wrote:Code: Select all
call :Converter &echo Converted value is %converted%
Your problem is immediate expansion. Variables are being replaced by their content while the line is read.
What u want is delayed expansion. Variables are being replaced by their content while the line is executed.
Code: Select all
setlocal enableDelayedExpansion
setlocal /?
pause
call :Converter &echo Converted value is !converted!
pause
Don't blame me, I put as much time in formulating an answer, as you put time in formulating a good question.

Re: Is it possible to add another command, same line as CALL
Posted: 05 Jul 2012 23:02
by foxidrive
Here you are MKA. Try this and then look at your posts.
It is obvious you *didn't* try your code.
Code: Select all
@echo off
Call :subroutine &echo subroutine complete
pause
goto :EOF
:subroutine
echo hello world
Re: Is it possible to add another command, same line as CALL
Posted: 05 Jul 2012 23:32
by MKANET
Hmmm... interesting. I thought for sure my second post clarified what I was actually having trouble with. I guess it didn't go without saying after all that I wasn't talking about the original example anymore
I think what confused me is already had a
setlocal enableDelayedExpansion in the beginning of my batch file. But thanks, at least now I know what its related to.
Ed Dyreen wrote:MKANET wrote:Yes, I was hoping that went without saying since I already clarified what I was trying to do (what you quoted).
No, I disagree, the previous exemplary code didn't exhibition any problem.
MKANET wrote:Call :subroutine &echo subroutine complete
But the new code you now present us with ( which is totally different ) does.
Your problem is immediate expansion. Variables are being replaced by their content while the line is read.
Code: Select all
call :Converter &echo Converted value is %converted%
What u are after is delayed expansion. Variables are being replaced by their content while the line is executed.
Code: Select all
setlocal enableDelayedExpansion
setlocal /?
pause
call :Converter &echo Converted value is !converted!
pause
Don't blame me, I put as much time in formulating an answer, as you put time in formulating a good question.

Re: Is it possible to add another command, same line as CALL
Posted: 06 Jul 2012 06:05
by Squashman
MKANET wrote:Hmmm... interesting. I thought for sure my second post clarified what I was actually having trouble with. I guess it didn't go without saying after all that I wasn't talking about the original example anymore
I think what confused me is already had a setlocal enableDelayedExpansion in the beginning of my batch file. But thanks, at least now I know what its related to.
You said NOTHING about using a variable in either of your first two posts. Using Delayed Expansion has also been explained to you a few times since you joined the forums.
If you read other threads on this forum you will see plenty of users on this forum tell other users that their questions need to be accurate with their REAL DATA! That means the batch file you are using and any other subsequent input you are using with the batch file. If you don't give us accurate DATA you get an inaccurate answer and waste everyone's time.