I've been trying to write a simple Windows batch file to open a video file on my Media PC. When you place a URL to a media file in the quotation marks after file: and hit enter the file opens on XBMC. This is what I have so far:
#echo off
set /P url=Enter video URL:
start http://xbmc:8080/jsonrpc?request={"jsonrpc":"2.0","method":"player.open",%%20"params":%%20{"item":{"file":""%url%""}}}
The webpage opens and the variable is substituted but my problem is that the quotation marks disappear. I've researched this and tried the backslash \, caret ^ and double quotes but none of these worked. A solution to this problem is greatly appreciated.
Also, I have around 10 minutes of experience with batch files so please be forgiving if the solution is simple!
Thanks!
In the same way that spaces have to be replaced with %%20, quotes need to be replaced with %%22. See this list for other substitutions - you'll be using the value from the "hx" column.
#echo off
set /P url=Enter video URL:
start http://xbmc:8080/jsonrpc?request={%%22jsonrpc%%22:%%222.0%%22,%%22method%%22:%%22player.open%%22,%%20%%22params%%22:%%20{%%22item%%22:{%%22file%%22:%%22%%22%url%%%22%%22}}}
You should wrap your entire URL in double quotes to have the inner double quotes escaped:
start "http://xbmc:8080/jsonrpc?request={"jsonrpc":"2.0","method":"player.open",%%20"params":%%20{"item":{"file":""%url%""}}}"
Hope this helps.
Related
I have tried creating a batch file that moves mods from the gta v directory to another when i need to play online. I wrote this so far:
move E:/Epic Games/GTAV/TrainerV.asi C:/Users/example/Desktop
I got this error:
The syntax of the command is incorrect.
Can someone tell me how to do it right? I would appreciate it.
To be able to operate with any file with a space in cmd/batch, you need to group them with quotes "" and since
E:\Epic Games\GTAV\TrainerV.asi
^ Here
has spaces, you need to surround it with quotes. A good practice is to have quotes anyways. The correct syntax is:
move "E:\Epic Games\GTAV\TrainerV.asi" "C:\Users\example\Desktop"
You have multiple issues with your current command.
First, paths containing spaces must be surrounded in double quotes.
Second, Windows uses the backslash \ instead of the forward slash / as the path separator. While the forward slash might be accepted in some cases, it won't work in all, so it's better to use the proper \.
The corrected version of your code would be
move "E:\Epic Games\GTAV\TrainerV.asi" C:\Users\example\Desktop
I have been looking around for a solution to this one, but so far I have been unsuccessful. I am trying to open two programs using a batch file. The problem is that both of the paths to these files contain spaces, and one of these paths is already enclosed in quotation marks. Because of the the second file (.gh file) does not open. I have already tried putting the second path in quotation marks, and using the \ character to escape the quotation marks, but without any result. Any help is appreciated.
#ECHO OFF
cd C:\Users\\Google Drive\Rhino Werk\MT1458\WIP
"C:\Program Files\Rhino 6\System\Rhino.exe" /nosplash /runscript="-grasshopper editor load document open C:\Users\<username>\Google Drive\Rhino Werk\MT1458\WIP\MT1458_HullGenerator_V2.64_NAKIJKMODEL.gh _enter" "C:\Users\<username>\Google Drive\Rhino Werk\MT1458\WIP\MT1458_HullGenerator_V2.59_001.3dm"
#ECHO OFF
cd /d "C:\Users\\Google Drive\Rhino Werk\MT1458\WIP"
"C:\Program Files\Rhino 6\System\Rhino.exe" /nosplash /runscript="-grasshopper editor load document open \"%userprofile%\Google Drive\Rhino Werk\MT1458\WIP\MT1458_HullGenerator_V2.64_NAKIJKMODEL.gh\" _enter \"%userprofile%\Google Drive\Rhino Werk\MT1458\WIP\MT1458_HullGenerator_V2.59_001.3dm\""
This would be following C++ argv rules of escaping inner double quotes with a backslash. Whether this works or not is unknown as I do not have or use Rhino.
I am new to batch files but was looking to create one that would use the tree command to write a .txt file of the directory in which the batch file is located and then convert that .txt file to a Word file or PDF that the every day user could view.
This was my attempt at the first part of the process;
tree %~dp0 > %~dp0/"Folder Contents.txt" /A /F
but this gave me an "Invalid Path" message in the .txt file
If anyone could point me in the right direction it would be greatly appreciated.
Thanks in advance for your help.
JosefZ has placed the correct command in the comments but I thought I would add a bit of an explanation here:
Think of how you path would look like with your command. It would be like C:\PathTo\Batch\/"FolderContent.txt" which actually is not a valid path.
%~dp0 will end with a \ so the / in the command from the question is syntactically incorrect.
Further the double quotes should be placed around the total path as JosefZ did in his comment. If you do not do that the path will contain these quotes and will be invalid.
JosefZ further added double quotes and a single . around and at the end of %~dp0 after your tree command. The quotes are there to include possible whitespaces into your folder-path and the . to include folders with subfolders as well. You will get an error message if you do not.
Last thing is that he placed the output file at the beginning of the command and got rid of spaces. You can basically place your output file anywhere however. Although you should notice that you should not contain spaces between > and your output-file-path.
I am trying to create a bat file to run testng from command prompt. Problem is that my path contains many folders with spaces in its name. I followed the step mentioned in How to write a full path in a batch file having a folder name with space? and added double quotes for the folder with space in its name but the issue is that the application is also considering the folder name with quotes and hence unable to find the given folder.
Here is my command.
set ProjectPath="C:\Test\ABC Online"
echo %ProjectPath%
set classpath=%ProjectPath%\bin;%ProjectPath%\Framework Jar Files\*
echo %classpath%
java org.testng.TestNG %ProjectPath%\testng.xml
but everytime getting an error "Error: Could not find or load main class org.testng.TestNG". In the above code when I echo Projectpath, I am getting something like this.
"C:\Test\ABC Online" (Double quotes)
If I change the folder name to ABC_Online and run the same command without double quotes, it work pretty fine.
Am I missing something. Please suggest.
In your set command line, the quotation marks are part of the value, and there are trailing spaces at your command line:
set ProjectPath="C:\Test\ABC Online"SPACESPACESPACESPACE
So the command line java org.testng.TestNG "%ProjectPath%\testng.xml" expands to this:
java org.testng.TestNG "C:\Test\ABC Online" \testng.xml
Use the following syntax so the spaces and the quotation marks do not become part of the variable value:
set "ProjectPath=C:\Test\ABC Online"
When using the value later, put quotes like this:
java org.testng.TestNG "%ProjectPath%\testng.xml"
I've written a .bat file to open chromium portable in to kiosk mode on the page I want like a full screen app. This works great. My problem is it doesn't work if it's in a folder with spaces in. I know I probably need to add quotes somehow but not sure how to do it using the %cd% command can anyone tell me how to make my .bat file work from any folder? The code is below:
#echo off
start %cd%\appdata\chromeportable.exe --kiosk %cd%\appdata\app.html
How can i edit it so that it will run from folders with spaces in the title!
I don't quite follow your question, but here are a few things to try
To change directory to a path with spaces use
cd "C:\folder\folder with spaces"
To start the batch file from a folder with spaces from another directory
"C:\folder\folder with spaces\openchromium.bat"
If this isn't what you are trying to do please improve your question.
Update
After posting your code I can see a possible issue. When you use start and the path in the first argument is quoted it will treat it as the title, to fix this you give it a blank title like this
start "" "%cd%\appdata\chromeportable.exe" "--kiosk %cd%\appdata\app.html"
Hope this helps