Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
testingbatch
- Posts: 7
- Joined: 19 Feb 2019 09:13
#1
Post
by testingbatch » 19 Feb 2019 09:25
Code: Select all
call "...\server.bat" start ifa
call "...\jar.exe" -cvfM "CDO.zip" "%1"
set jobid = "...\curl.exe" -X POST -i -T "CDO.zip" "http://localhost:9080/rest/ifa/v1/triaged-assessments"
for /f "tokens=*" %%a in ('%jobid% ^|findstr ".*-.*-.*-.*"') do set "output=%%a"
echo %output%
call "...\curl.exe" -X GET --header "Accept: application/octet-stream" --output "CDOout.zip" "http://locahost:9080/rest/ifa/v1/triaged-assessments/%jobid%"
The output:
HTTP/1.1 200 OK
Date: Tue, 19 Feb 2019 15:12:01 GMT
X-Powered-By: Servlet/3.1
Content-Type: text/plain
Date: Tue, 19 Feb 2019 15:12:01 GMT
Content-Length: 36
fdfba1cf-9b97-457e-b1d5-076dc8393ecf| was unexpected at this time.
Hello guys, how are you doing? I'm new at batch and i'm trying to get the random string from the header (with the for condition) but always returns the same type of error:
| was unexpected at this time..
What I have done was send the output to a new .txt file, save it into a variable then delete the file, but I want to simplify this mechanism so i'm trying to save that string on a variable because i need that to execute the next call.
Thanks in advance.
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#2
Post
by Squashman » 19 Feb 2019 11:37
Remove the spaces in the SET command for the JOBID variable. If you have a space on the left of the equals symbol it becomes part of the variable name. If you have a space on the right of the equals symbol it becomes part of the value.
-
testingbatch
- Posts: 7
- Joined: 19 Feb 2019 09:13
#3
Post
by testingbatch » 20 Feb 2019 03:20
Squashman wrote: ↑19 Feb 2019 11:37
Remove the spaces in the SET command for the JOBID variable. If you have a space on the left of the equals symbol it becomes part of the variable name. If you have a space on the right of the equals symbol it becomes part of the value.
Hello Squashman, and thanks for the feedback. I did what you say to do and now the program is returning a error
type of the system cannot find the path specified (?).
Output:
Code: Select all
D:\>call "...\server.bat" start ifa
Starting server ifa.
Server ifa started.
adding: Appscan/Scan/20190212_123048.ozasmt(in = 16177326) (out= 998720)(deflated 93%)
The system cannot find the path specified.
ECHO is off.
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
Stopping server ifa.
What I noticed is that happens only in the for condition.
Code: Select all
call "...\server.bat" start ifa
call "...\jar.exe" -cvfM "CDO.zip" "%1"
set jobid="...\curl.exe" -X POST -i -T "CDO.zip" "http://localhost:9080/rest/ifa/v1/triaged-assessments"
for /f "tokens=*" %%a in ('%jobid% ^|findstr ".*-.*-.*-.*"') do set "output=%%a"
echo %output%
call "....\curl.exe" -X GET --header "Accept: application/octet-stream" --output "CDOout.zip" "http://localhost:9080/rest/ifa/v1/triaged-assessments/%jobid%"
call "...\jar.exe" -xvf "CDOout.zip"
call "...\server.bat" stop ifa
pause
My code is like this right now. I didn't mention this before but i need the random string output of the header to copy into a variable and use it in the next call.
Again, thanks for the support/feedback.
-
penpen
- Expert
- Posts: 2009
- Joined: 23 Jun 2013 06:15
- Location: Germany
#4
Post
by penpen » 24 Feb 2019 03:03
On some first tests it seems (at last on my win 10) the "for/f"-command doesn't accept the ".\" and "..\" parts for the command you want it to execute, as long as you don't use a volume descriptor.
Just remove all those "...\","....\", "............................\" parts (that are reduced to ".\").
Btw why do you use those in your commands (i don't see any reason in doing so)?
penpen