3

I want to modify the command somecommand >> file1.txt in a way that only the first line of the command output be saved to the file.

How is it possible, what script is needed?

| improve this question | | | | |
2

Edited simplified, same idea, less code

somecommand | cmd /q /v:on /c "set/p .=&echo(!.!" >> file1.txt

edited to adapt to comments. To include in a vbs file

WScript.CreateObject("WScript.Shell").Run "cmd /q /c ""somecommand | cmd /q /v:on /c ""set/p .=&echo(!.!"" >> file1.txt "" ",0
| improve this answer | | | | |
  • Can you please tell me how I should put this command in a .VBS file? – Behnam Sep 24 '14 at 9:17
  • @Campiador, answer updated. – MC ND Sep 24 '14 at 9:36
  • thanks, this is my command: aapt dump badging box.apk, should I just put it in thecommand without any change? – Behnam Sep 24 '14 at 9:36
  • especially, the part with box.apk, I want to use a File Object – Behnam Sep 24 '14 at 9:43
  • 1
    @Campiador, WScript.CreateObject("WScript.Shell").Run "cmd /q /c "" aapt dump badging """+oAPKFile.Path+""" | cmd /q /v:on /c ""set/p .=&echo(!.!"" >> file1.txt "" ",0 – MC ND Sep 24 '14 at 10:02
2

First write all the output in the file:

somecommand > file2.txt

After that save only the first row in the file:

set /p firstline=<file2.txt
echo %firstline% > file1.txt
| improve this answer | | | | |
  • Hmm thanks, actually I may add this to an existing file with >>, so if I do what you told I will miss all the previous reports. – Behnam Sep 24 '14 at 8:05
  • Thist is not problem at all, just use a temporary file2.txt - I have edited. The point is, the first row of the output is in the variable %firstline% , that is what you need to use with >> – duDE Sep 24 '14 at 8:16
  • this is my command: aapt dump badging god.apk > file2.txt do you know how I should modify it in order to put it in .vbs script? – Behnam Sep 24 '14 at 8:41
  • 1
    Try something like WshShell.Run("aapt dump badging god.apk > file2.txt", 0, true); – duDE Sep 24 '14 at 8:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.