0
@ECHO OFF
set "str1=cd"
set "str2=%~dp0"
set "str5=CPCE Client\EfileServiceClient""
set "str4=%str1% %str2%%str5%"
Echo.%str4%

i want to execute the command which is existed in variable "str4" how to execute it....

1
  • If str5 didn't have a space in it, I'd recommend simply using %str4% by itself as a command. Commented Sep 10, 2015 at 22:47

2 Answers 2

1

Simply type %str4% in the command prompt or state it in a batch file to execute its value as a command line.

However, there are some issues in your code:

  • there is a closing " too much at the str5 assignment, which must be removed; otherwise, the value of str5 equaled CPCE Client\EfileServiceClient";
  • there is a space in the value of str5; spaces must be handled correctly, as you would type the command in the command prompt; arguments with spaces should be enclosed within "";
    (actually, for the cd command (in str1), spaces do not cause any problems, so it would also work without ""; however, for most commands, spaces most probably will cause troubles)

The following adapted code will work:

@echo off
set "str1=cd"
set "str2=%~dp0"
set "str5=CPCE Client\EfileServiceClient"
set "str4=%str1% "%str2%%str5%""
%str4%
Sign up to request clarification or add additional context in comments.

Comments

0

You could do this:

echo %str4% > temp.cmd
call temp.cmd
del temp.cmd

Although I think it would make more sense not to add cd to the string and do this instead:

cd %str4%

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.