Was unexpected at this time ошибка

I am getting this error:

( was unexpected at this time

The error occurs after accepting the value of a. I tried and checked for null values that could cause such a problem,, but was unsuccessful.

echo off
cls
title ~USB Wizard~
echo What do you want to do?
echo 1.Enable/Disable USB Storage Devices.
echo 2.Enable/Disable Writing Data onto USB Storage.
echo 3.~Yet to come~.

set "a=%globalparam1%"
goto :aCheck
:aPrompt
set /p "a=Enter Choice: "
:aCheck
if "%a%"=="" goto :aPrompt
echo %a%

IF %a%==2 (
title USB WRITE LOCK
echo What do you want to do?
echo 1.Apply USB Write Protection
echo 2.Remove USB Write Protection
::param1
set "param1=%globalparam2%"
goto :param1Check
:param1Prompt
set /p "param1=Enter Choice: "
:param1Check
if "%param1%"=="" goto :param1Prompt

if %param1%==1 (
REG ADD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\StorageDevicePolicies\ /v WriteProtect /t REG_DWORD /d 00000001 
echo USB Write is Locked!
)
if %param1%==2 (
REG ADD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\StorageDevicePolicies\ /v WriteProtect /t REG_DWORD /d 00000000
echo USB Write is Unlocked! 
)
)
pause

John Smith's user avatar

John Smith

7,2536 gold badges49 silver badges61 bronze badges

asked Jul 1, 2013 at 20:00

user2540289's user avatar

1

You are getting that error because when the param1 if statements are evaluated, param is always null due to being scoped variables without delayed expansion.

When parentheses are used, all the commands and variables within those parentheses are expanded. And at that time, param1 has no value making the if statements invalid. When using delayed expansion, the variables are only expanded when the command is actually called.

Also I recommend using if not defined command to determine if a variable is set.

@echo off
setlocal EnableExtensions EnableDelayedExpansion
cls
title ~USB Wizard~
echo What do you want to do?
echo 1.Enable/Disable USB Storage Devices.
echo 2.Enable/Disable Writing Data onto USB Storage.
echo 3.~Yet to come~.

set "a=%globalparam1%"
goto :aCheck
:aPrompt
set /p "a=Enter Choice: "
:aCheck
if not defined a goto :aPrompt
echo %a%

IF "%a%"=="2" (
    title USB WRITE LOCK
    echo What do you want to do?
    echo 1.Apply USB Write Protection
    echo 2.Remove USB Write Protection

    ::param1
    set "param1=%globalparam2%"
    goto :param1Check
    :param1Prompt
    set /p "param1=Enter Choice: "
    :param1Check
    if not defined param1 goto :param1Prompt
    echo !param1!

    if "!param1!"=="1" (
        REG ADD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\StorageDevicePolicies\ /v WriteProtect /t REG_DWORD /d 00000001 
        echo USB Write is Locked!
    )
    if "!param1!"=="2" (
        REG ADD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\StorageDevicePolicies\ /v WriteProtect /t REG_DWORD /d 00000000
        echo USB Write is Unlocked! 
    )
)
pause
endlocal

answered Jul 1, 2013 at 21:33

David Ruhmann's user avatar

David RuhmannDavid Ruhmann

11.1k4 gold badges37 silver badges47 bronze badges

1

Oh, dear. A few little problems…

As pointed out by others, you need to quote to protect against empty/space-containing entries, and use the !delayed_expansion! facility.

Two other matters of which you should be aware:

First, set/p will assign a user-input value to a variable. That’s not news — but the gotcha is that pressing enter in response will leave the variable UNCHANGED — it will not ASSIGN a zero-length string to the variable (hence deleting the variable from the environment.) The safe method is:

 set "var="
 set /p var=

That is, of course, if you don’t WANT enter to repeat the existing value.
Another useful form is

 set "var=default"
 set /p var=

or

 set "var=default"
 set /p "var=[%var%]"

(which prompts with the default value; !var! if in a block statement with delayedexpansion)

Second issue is that on some Windows versions (although W7 appears to «fix» this issue) ANY label — including a :: comment (which is a broken-label) will terminate any ‘block’ — that is, parenthesised compound statement)

answered Jul 2, 2013 at 1:05

Magoo's user avatar

MagooMagoo

77.4k8 gold badges62 silver badges84 bronze badges

4

you need double quotes in all your three if statements, eg.:

IF "%a%"=="2" (

@echo OFF &SETLOCAL ENABLEDELAYEDEXPANSION
cls
title ~USB Wizard~
echo What do you want to do?
echo 1.Enable/Disable USB Storage Devices.
echo 2.Enable/Disable Writing Data onto USB Storage.
echo 3.~Yet to come~.


set "a=%globalparam1%"
goto :aCheck
:aPrompt
set /p "a=Enter Choice: "
:aCheck
if "%a%"=="" goto :aPrompt
echo %a%

IF "%a%"=="2" (
    title USB WRITE LOCK
    echo What do you want to do?
    echo 1.Apply USB Write Protection
    echo 2.Remove USB Write Protection
    ::param1
    set "param1=%globalparam2%"
    goto :param1Check
    :param1Prompt
    set /p "param1=Enter Choice: "
    :param1Check
    if "!param1!"=="" goto :param1Prompt

    if "!param1!"=="1" (
         REG ADD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\StorageDevicePolicies\ /v WriteProtect /t REG_DWORD /d 00000001
         USB Write is Locked!
    )
    if "!param1!"=="2" (
         REG ADD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\StorageDevicePolicies\ /v WriteProtect /t REG_DWORD /d 00000000
         USB Write is Unlocked!
    )
)
pause

answered Jul 1, 2013 at 20:19

Endoro's user avatar

EndoroEndoro

37k8 gold badges50 silver badges63 bronze badges

3

If you are getting this error on your IF statement check if used or not your double equals to compare your variable.

Eg.

IF [%checkresult%]=1 GOTO INVALID

This throws «=1 was unexpected at this time.»

To correct this add another equals sign.

IF [%checkresult%]==1 GOTO INVALID

answered Jun 12, 2021 at 13:08

Ozan BAYRAM's user avatar

Ozan BAYRAMOzan BAYRAM

2,7901 gold badge28 silver badges35 bronze badges

I was getting that same error using Netbeans as my IDE. I realized that my base folder in Windows had (1) imbedded in the path of my project, this happened when I copied the original zip file causing the (1) to be added to the file which in turn was blowing up the build process.

My fix,

  1. close the project
  2. Close IDE
  3. Clean up path name for project, remove any funny characters
  4. reimport project and build

answered Jul 2 at 13:45

panatechnica's user avatar

SurelL

@SurelL

Нагрузочный тестировщик

Всем привет!

Пишу батник вот с таким кодом:

@echo off
if java -jar "SOAPClientDummy02.jar" input.txt | find /i "Stubs on dummy02 work correctly" goto success
echo Something gooes with errors on dummy02
:success
echo Stubs on dummy02 work correctly
pause

При выполнении данного батника выходит ошибка:
-jar was unexpected at this time

Подскажите, пожалуйста, в чем причина?


  • Вопрос задан

  • 336 просмотров

Пригласить эксперта

Потому что у вас вызов java … стоит в операторе if.
Я не понял что вы хотите этим сказать.
В любом случае это не корректно — if не может вызывать внешних программ как в bash.
О чем и сообщается в ошибке, правда ошибка может показаться несколько нелепой на первый взгляд, но на второй уже все нормально :-)

кавычки потеряли. Вы же хотите обработать код выполнения

java -jar "SOAPClientDummy02.jar" input.txt | find /i "Stubs on dummy02 work correctly"

? вот его и надо убрать в кавычки


  • Показать ещё
    Загружается…

21 сент. 2023, в 20:54

10000 руб./за проект

21 сент. 2023, в 20:40

20000 руб./за проект

21 сент. 2023, в 19:28

10000 руб./за проект

Минуточку внимания

Stephan has provided the crucial pointer:

It sounds like you have a broken autorun command defined for cmd.exe; that is, your registry defines a command that is automatically executed whenever you call cmd.exe, and that command causes the syntax error you’re seeing.

Note that such commands are executed irrespective of whether you open an interactive cmd session or invoke via a batch file or pass a command to cmd with /C.

Passing /D to cmd bypasses any autorun commands.

There are two locations in the registry where such a command can be defined, one at the local-machine level (which applies to all users),
HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor, and another for the current user only,
HKEY_CURRENT_USER\Software\Microsoft\Command Processor, in a value named AutoRun.
If commands are defined in both locations, the HKEY_LOCAL_MACHINE‘s commands run first.

To list any defined autorun commands:

Get-ItemProperty -ea Ignore ('HKCU:', 'HKLM:' -replace '$', '\Software\Microsoft\Command Processor') AutoRun

You can use the following PowerShell snippet to remove autorun commands from both locations, but note that you’ll have to run it with elevation (as administrator), if a local-machine value is present:

Get-ItemProperty -ea Ignore ('HKCU:', 'HKLM:' -replace '$', '\Software\Microsoft\Command Processor') AutoRun |
  Remove-ItemProperty -Name AutoRun -WhatIf

Note: The -WhatIf common parameter in the command above previews the operation. Remove -WhatIf, once you’re sure the operation will do what you want.

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.

Already on GitHub?
Sign in
to your account

Closed

bububut opened this issue

Aug 17, 2020

· 27 comments

Assignees

@ericsnowcurrently

Labels

bug

Issue identified by VS Code Team member as probable bug

info-needed

Issue requires more information from poster

Comments

@bububut

Environment data

  • VS Code version: 1.48.0
  • Extension version (available under the Extensions sidebar): v2020.8.101144
  • OS and version: Windows 10 Pro 2004 build 19041.450

Expected behaviour

right click in Python file and choose «Run Python File in Terminal» to get the file run

Actual behaviour

it inserts a ‘&’ symbol at the beginning of the command and the commands failed with «& was unexpected at this time.»

my terminal is cmd.exe

It’s the same problem as #5916
I believe it has been solved and that issue is closed, don’t know why it happens again now

@bububut
bububut

added

triage-needed

Needs assignment to the proper sub-team

bug

Issue identified by VS Code Team member as probable bug

labels

Aug 17, 2020

@ghost
ghost

removed
the

triage-needed

Needs assignment to the proper sub-team

label

Aug 17, 2020

@ericsnowcurrently

@bububut, thanks for letting us know about this. I was not able to reproduce the problem with the following steps:

  1. change my default terminal to «cmd.exe»
  2. right-click in the .py file’s editor window
  3. select «Run Python File in Terminal»

Here’s what I see in my terminal pane:

C:\Users\...\my-workspace>"C:/Program Files (x86)/Microsoft Visual Studio/Shared/Python37_64/python.exe" c:/Users/my-workspace/hello-world.py
Hello World!

What is the actual text in your terminal pane?

@bububut

@ericsnowcurrently I cannot reproduce the problem myself after I restarted vscode today, so I’ll close the ticket. Thanks for your help!

@ashishmahalka

I am facing the same problem today. I have the below vs code version.
Version: 1.51.1 (user setup)
Commit: e5a624b788d92b8d34d1392e4c4d9789406efe8f
Date: 2020-11-10T23:34:32.027Z
Electron: 9.3.3
Chrome: 83.0.4103.122
Node.js: 12.14.1
V8: 8.3.110.13-electron.0
OS: Windows_NT x64 10.0.18363

image

@huntfx

I just randomly started getting the issue in 1.50.1

B:\Projects\Code\Python\project>& py "b:/Projects/Code/Python/project/script.py"
& was unexpected at this time.

B:\Projects\Code\Python\project>& "C:/Program Files/Python37/python.exe" "b:/Projects/Code/Python/project/script.py"
& was unexpected at this time.

It’s a bit annoying trying to fix, as all the issues keep getting closed without any actual solution

@vtasca

Getting exact same issue today, this doesn’t seem to have been resolved.

Version: 1.53.2 (user setup)
Commit: 622cb03f7e070a9670c94bae1a45d78d7181fbd4
Date: 2021-02-11T11:48:04.245Z
Electron: 11.2.1
Chrome: 87.0.4280.141
Node.js: 12.18.3
V8: 8.7.220.31-electron.0
OS: Windows_NT x64 10.0.19041

@huntfx

Someone very helpfully mentioned a fix which worked in my case btw.
You just need to re-select your terminal via the dropdown menu.

image

@pasquale90

For me the issue resolved by redirecting the console path to the target file that I would try to execute. Both cmd and python console in VSCODE are targeting the same target path.

@chupocro

Same here.

VS Code: 1.56.0
Python extension: v2021.4.765268190

Everything worked well until some recent update. Now there isn’t Select Default Shell command anymore, there is Select Default Profile where Command Prompt could be selected but the problem is Python extension is (instead of activate.bat) trying to run a PowerShell virtualenv activation script when using cmd and is adding & in front of the command.

Example:

path_to_project>& path_to_project/env/Scripts/Activate.ps1
& was unexpected at this time.
Cubostar, zseddek, LSgeo, Sunillad08, petersen-f, eternalphane, AAnusekhar, Nawodawi, BunnyEaredFriend, HugoxSaraiva, and 2 more reacted with thumbs up emoji

@Cubostar

For me the issue resolved by redirecting the console path to the target file that I would try to execute. Both cmd and python console in VSCODE are targeting the same target path.

How do you redirect the console path?

@LSgeo

#16175 is the currently open issue about this — I’m getting the same issue. Temporarily need to use powershell as the integrated terminal.

@plusk-dev

I am getting the same issue. Also to mention, that when I try to format my Python files using Shift + Alt + F, it popped an alert:
image
When I click «Yes», the same error occurs
image
Same goes for running python files in the terminal.

@pasquale90

@Cubostar Soz but it;s been so long and I really can t remember what was the exact process that I followed… I check my integrated terminal configurations though and I am temped to send you a screenshot.. (ctl-shift-P and type terminal.integrated.default -> edit in settings.json). Make sure you are in the right console directory when you apply changes in your settings (both Workspace and User).
KEEP A BACKUP COPY of the text stored in your settings.json before changing anything..

image

After changing the file, right click on file.py and choose «Open in integrated terminal» option.
pls let me know if that was it.

ps:If that fails, just re edit the file and paste the previous values stored before changing anything.

@csmontt

I am getting the same error.

@pbthodges

Me too
fixed it by adding the line «terminal.integrated.shell.windows»: «C:\Windows\System32\cmd.exe» (including double quotes)
as the second to last line, just before the last closing brace in
«C:\Users<yourusername>\AppData\Roaming\Code\User\settings.json»

@AAnusekhar

iam also getting the same error

@0yv1nd

Me too
fixed it by adding the line «terminal.integrated.shell.windows»: «C:\Windows\System32\cmd.exe» (including double quotes)
as the second to last line, just before the last closing brace in
«C:\Users\AppData\Roaming\Code\User\settings.json»

I did this and edited the file in MS VC, so the full line looked like this (due to special char):

bilde

Worked for me!

@pbthodges

Indeed, I didn’t notice the double backslashes weren’t included when I copied and pasted the string.
I’m trying again out of curiosity.
«terminal.integrated.shell.windows»: «C:\Windows\System32\cmd.exe»

@pbthodges

«terminal.integrated.shell.windows»: «C:\\Windows\\System32\\cmd.exe»

There, you need 3 backslashes in the original string to generate 2 on the web page.

@ansonnn07

"python.condaPath": "C:\\Users\\<your_pc_username>\\anaconda3\\Scripts\\conda.exe",
"python.terminal.activateEnvironment": true,

I had a friend having the same problem today and I told him to add these two lines into the settings.json file and it solved the problem. These settings just let the VS Code terminal know the right path for Anaconda, and also activate the environment automatically when you run your Python file in the terminal.

@ppostnov

image
This is helped me for bash terminal. I have added it to global vscode settings -> settings.json

@yMayanand

Me too
fixed it by adding the line «terminal.integrated.shell.windows»: «C:\Windows\System32\cmd.exe» (including double quotes)
as the second to last line, just before the last closing brace in
«C:\Users\AppData\Roaming\Code\User\settings.json»

yeah this worked for me too.

@Mohamed3nan

image
This is helped me for bash terminal. I have added it to global vscode settings -> settings.json

worked for me but .bash_profile is not loading :/

@leo-cube

Screenshot (172)>
I just randomly started getting the issue in 1.50.1

B:\Projects\Code\Python\project>& py "b:/Projects/Code/Python/project/script.py"
& was unexpected at this time.

B:\Projects\Code\Python\project>& "C:/Program Files/Python37/python.exe" "b:/Projects/Code/Python/project/script.py"
& was unexpected at this time.

It’s a bit annoying trying to fix, as all the issues keep getting closed without any actual solution

i.) SOLUTION: Change the setting back -> Configure terminal settings to -> Integrated
and then come to the file and delete all the other interpreter that you have opened until the whole dialog box is gone.

ii.) Now right click and run on terminal. VS code must be able to print.

@ppostnov

image
This is helped me for bash terminal. I have added it to global vscode settings -> settings.json

worked for me but .bash_profile is not loading :/

Do you have bash on your machine ?

@Mohamed3nan

image
This is helped me for bash terminal. I have added it to global vscode settings -> settings.json

worked for me but .bash_profile is not loading :/

Do you have bash on your machine ?

yes

@StephD

I just had the same problem after removing the line that everyone is talking about.
And yeah, it’s fix by putting this line back.
BUT

  1. Without this setting line. The code is succefully executed in the PowerShell of windows, even with the ‘&’ that is a problem.
  2. Like on every screen, microsoft say it’s deprecated and will change in the future. So will need to find an alternative solution later.

Would be great to find the actual bug or problem that need to be solved

@brianleect

Just got this error as well. Happened after I couldn’t interrupt a process running in terminal using Ctrl+C and forcefully closed it.

Code is able to be ran as per normal using powershell though

@github-actions
github-actions
bot

locked as resolved and limited conversation to collaborators

Sep 21, 2021

Labels

bug

Issue identified by VS Code Team member as probable bug

info-needed

Issue requires more information from poster

RRS feed

  • Remove From My Forums
  • Question

  • How do I get my Developer Command Prompt to run csc again?

    When I open my Developer Command Prompt for VS it gives me this error within the window, «\Microsoft was unexpected at this time» I am new with Visual Studio and Command Prompt. 

All replies

  • Hi,

    Welcome to MSDN forum.

    It seems your PATH got modified recently and now contains some folder path with quotation marks inside. Please check how your PATH looks like, type
    echo %PATH% in command prompt and check it if there is one entry of PATH was indeed enclosed in double quotes. You just need to remove those double quotes and run the Developer Command Prompt again.

    https://stackoverflow.com/questions/8756828/visual-studio-command-prompt-gives-common-was-unexpected-at-this-time

    Best regards,

    Joyce


    Please remember to click «Mark as Answer» the responses that resolved your issue, and to click «Unmark as Answer» if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints
    to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by

      Tuesday, March 20, 2018 6:22 AM

    • Unproposed as answer by
      Sara LiuMicrosoft contingent staff
      Wednesday, March 21, 2018 8:27 AM
    • Proposed as answer by
      Sara LiuMicrosoft contingent staff
      Wednesday, March 21, 2018 8:27 AM

Понравилась статья? Поделить с друзьями:
  • Was he play tennis last week исправь ошибки
  • War thunder ошибка запуска 1243
  • War thunder фатальная ошибка
  • War thunder ошибка 80130182 сервер авторизации недоступен
  • War thunder ошибки после обновления