I'm trying to run a code generating script from terminal within vs code on a mac, but each time I get the the following error:
cmd: "..\node_modules\.bin\nswag" run
cmd : The term 'cmd' is not recognized as the name of a cmdlet,
function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that
the path is correct and try again.
At ...
here's the ps1 script I was trying to run:
$invocation = (Get-Variable MyInvocation).Value
$directorypath = Split-Path $invocation.MyCommand.Path
Set-Location $directorypath
$cmdString = """" + "..\node_modules\.bin\nswag" + """" + " run";
Write-Host 'cmd:' $cmdString
cmd /c $cmdString
Related
How can I assign with in Rscript to pause until the command prompt is open?
I am running a Rscript where a batch file will be executed through command prompt. Later I want to copy a product of executed batch file to another folder. However, Rscript tries to copy while it is being written.
This batch file will open multiple cmd prompts to execute multiple files, so I don't want to use "shell", "system", or "system2" instead of "shell.exec2".
lapply(1:num_cores, function(o) {
## batch file location
loc <- paste0(projectfolder_location, pp, "\\ppfolder_", o, ".Sufi2.SwatCup")
## executing batch file
shell.exec2(paste0(pp_folder, "\\SUFI2_Run.bat"))
})
#PAUSING HERE until cmd prompt is open!!
file.copy(list.files(
path=paste0(projectfolder_location, pp, "\\ppfolder_", 1, ".Sufi2.SwatCup"),
pattern="Name.out$", full.name=TRUE), projectfolder, overwrite=TRUE)
I'm new to R and I'm stuck in a very simple task.
I want to run an R script from console, but I want the script to be able to read user inputs.
This is how I'm reading from the script:
library = readLines(n = 1L)
if(library == "1")
{
library = "GUDHI"
}
And this is how I'm running my script from R-Portable with a .bat:
#echo on
cd..
cd..
cd..
cd..
cd..
PATH C:\Users\MyUser\Desktop\App\RFolder\R-Portable\App\R-Portable\bin;%path%
cd C:\Users\MyUser\Desktop\App\RFolder
Rscript Phom.R 1
pause
When I run this .bat it throws an error (Argument is of length zero):
As if the console didn't wait for user input.
The problem is not the .bat code. If I remove the readLines functions from my script and hardcode the input, it works perfectly. I also tried the readline function with no success.
Thanks.
Solution for Interactive R script from Windows CMD:
cat("Prompt Message: ")
library = readLines(con = "stdin", 1)
I'm not sure if the prompt MUST end with ": ", but I had trouble when I removed that piece of string.
This worked for me, I hope this helps somebody.
I would like to set the working directory of the command prompt using the function system2 in R and I got the following error:
system2("cmd.exe", args = paste("cd", "Users/AKatherine/Downloads", sep = " "))
'Akatherine' is not recognized as an internal or external command,
operable program or batch file.
Also, I tried to run this
system2("cmd.exe", args = "java -mx150m -cp "*;" edu.stanford.nlp.parser.lexparser.LexicalizedParser -outputFormat "penn,typedDependencies" -outputFormatOptions "basicDependencies" edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz ./Test/input.txt")
and got the following error:
Error: unexpected ';' in "system2("cmd.exe", args = "java -mx150m -cp "*;"
Do anyone know why? Can anyone help me with this?
For the second part of my question, I tried using the shell function instead of the system2 function and I got the same output that I observe when I type in the same command in the command prompt. I used:
shell(cmd = "java -mx150m -cp \"*;\" edu.stanford.nlp.parser.lexparser.LexicalizedParser -outputFormat \"penn,typedDependencies\" -outputFormatOptions \"basicDependencies\" edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz ./Test/input.txt", shell = "cmd.exe")
instead of
system2("cmd.exe", args = "java -mx150m -cp \"*;\" edu.stanford.nlp.parser.lexparser.LexicalizedParser -outputFormat \"penn,typedDependencies\" -outputFormatOptions \"basicDependencies\" edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz ./Test/input.txt")
I am trying to zip a folder from an asp page. This is my code:
zipFolderName=folderName &"Zipped.zip"
command="cd C:\Program Files\7-Zip & "
command = command & "7z a -tzip " & zipFolderName & " """ & folderName & """"
Response.Write command
set objshell = Server.CreateObject("WScript.shell")
objShell.exec (command)
set objshell=nothing
The command that is written in the Response.Write is
cd C:\Program Files\7-Zip & 7z a -tzip D:/saveAll/DocumentsZipped.zip "D:/saveAll/Documents"
When I run this command in a cmd window it works just fine. But my asp page shows an error:
WshShell.Exec error '80070002'
The system cannot find the file specified.
The error is on the objShell.exe command-line.
What am I doing wrong? Please help!
You need to put C:\Program Files\7-Zip between double quotes, because the path contains a space. Also, cd and & are CMD-builtins, so you need to run the command line in CMD.
Change this:
command="cd C:\Program Files\7-Zip & "
into this:
command = "%COMSPEC% /c cd ""C:\Program Files\7-Zip"" & "
I am trying to run this code:
SendKeys "copy /b /y " & outputfile & " " & printerid & "{Enter}", 1.
It runs fine in Windows XP but in Windows 7 it gives an error.
I am trying to copy a string into cmd and execute it.
The "{Enter}" part is giving error.
Please help.
A quick test on Windows 7 gives me:
'sendkeys' is not recognized as an internal or external command,
operable program or batch file.
If that's the same error that you're getting, it means you don't have the program. Try copying it over from XP and see if that works.
If you've already copied it, it might not be in your PATH. Try this:
set PATH=%PATH%;C:\Path\to\SendKeys\
where C:\Path\to\SendKeys is the folder that contains SendKeys.exe.