Is it possible to add another command, same line as CALL :

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
MKANET
Posts: 160
Joined: 31 Mar 2012 21:31

Is it possible to add another command, same line as CALL :

#1 Post by MKANET » 05 Jul 2012 19:32

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Is it possible to add another command, same line as CALL

#2 Post by foxidrive » 05 Jul 2012 20:17

Did you try this?


(Call :subroutine ) & echo subroutine complete

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Is it possible to add another command, same line as CALL

#3 Post by Ed Dyreen » 05 Jul 2012 20:22

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, :)

MKANET
Posts: 160
Joined: 31 Mar 2012 21:31

Re: Is it possible to add another command, same line as CALL

#4 Post by MKANET » 05 Jul 2012 21:14

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, :)

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Is it possible to add another command, same line as CALL

#5 Post by foxidrive » 05 Jul 2012 21:28

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?

MKANET
Posts: 160
Joined: 31 Mar 2012 21:31

Re: Is it possible to add another command, same line as CALL

#6 Post by MKANET » 05 Jul 2012 22:13

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?

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Is it possible to add another command, same line as CALL

#7 Post by Ed Dyreen » 05 Jul 2012 22:41

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. :D

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Is it possible to add another command, same line as CALL

#8 Post by foxidrive » 05 Jul 2012 23:02

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

MKANET
Posts: 160
Joined: 31 Mar 2012 21:31

Re: Is it possible to add another command, same line as CALL

#9 Post by MKANET » 05 Jul 2012 23:32

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. :D

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Is it possible to add another command, same line as CALL

#10 Post by Squashman » 06 Jul 2012 06:05

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.

Post Reply