Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

9001.

Solve : batch, variables, and images?

Answer»

Hello world,
first POST for me here.

I've a problem about identify if an IMAGE is portrait or landscape...

Find a program that tell me meseurement in this FORMAT: myprog.exe test.jpg

[IPTCFIELDS]
3:40 = 256
3:50 = 171


So i write a small batch that find 2 VALUE (256,171) and PUT into a variable:

myprog.exe %1 -ds | for /f "Tokens=1-2 Delims==" %%e in ('find /I "3:40 ="') do set g=%%f
myprog.exe %1 -ds | for /f "Tokens=1-2 Delims==" %%s in ('find /I "3:50 ="') do set h=%%t



all seems to work but in my environment %g% and %h% are not present.

Anyone can help me?

A.Try

for /f "Tokens=1,2,3 Delims==" %%e in ('myprog.exe %1 -ds | find /I "3:40 ="') do set g=%%f

9002.

Solve : Problem Echoing a Digit to a File?

Answer»

Hi,

I APOLOGIZE if this has been covered before, but I've been searching for 2 days for a solution to no avail. I've wasted enough time on it, so I'm going to go ahead and ask.

The root of the problem is this:

echo 9> myfile.txt

The 9 (or any single digit for that matter) and the > next to each other cause the command to be interpreted incorrectly.


I've found it easy enough to overcome this by "escaping" the 9, ie:

echo ^9> myfile.txt

However, here's the rub, what I'm actually TRYING to do is echo a variable. The variable is set by the user with the SET /P command. The user is prompted to type in the path to their Flight Simulator INSTALLATION which is then set as the variable %fspath%. To avoid the user having to type the path each time he runs the .bat file, I'm attempting to store it (along with some other variables) in an .ini file. When the .bat file is run, the .ini is copied to temp.bat which is then called by the main .bat to set the variables. Something like this:

:start
if not exist myfile.ini goto firstrun
copy myfile.ini temp$$$.bat
call temp$$$.bat
del temp$$$.bat
goto menu1

:firstrun
set /p fspath=Please type the path to your FS installation:
echo set fspath=%fspath%> myfile.ini
copy myfile.ini temp$$$.bat
call temp$$$.bat
del temp$$$.bat
goto menu1

The problem is that typically the path to the user's FS installation is "[drive]:\Program Files\Microsoft Games\Flight Simulator 9" and because of the "9" at the end of the directory name, nothing at all gets written to the myfile.ini. Any other directory name seems to work fine.

I need some way "escape" the 9 in %fspath%, but short of instructing the user to insert the caret character before the 9 while typing the path, I'm drawing a blank. Any suggestions?

Thanks,
JimTry:

echo 9 > myfile.txt

note the space between 9 and >Quote from: Dusty on October 04, 2007, 12:49:09 AM

Try:

echo 9 > myfile.txt

note the space between 9 and >

This will (probably) echo the trailing space too.
Try this
>myfile.txt echo 9


GrahamYES!! That's exactly what I needed, Graham! Thank you so much. I had no idea you could do that. That actually solved another problem I had too. This batch stores settings "profiles" for starting Flight Simulator and the user is prompted to give each profile a name. My only hope before this was that no one ever chose a name like "Profile 4" because obviously the same problem rears it's ugly HEAD when trying to store the name to the .ini file. Now I don't have to worry about, they can name it whatever they want.

Went through and changed 48 occurances in this 1200+ line batch file and everything works perfectly now. Again, a very sincere thank you.

Dusty,
Graham's correct in that the space between the 9 and the > CAUSED the trailing space to be echoed to the .ini file. Oddly enough it still worked throughout the rest of the batch file even though it was effectively calling up the program with "...Flight Simulator 9 \fs9.exe" (note the space). The problem was when the user names or renames a profile the .ini gets completely re-written and echo %fspath% > myfile.ini adds a trailing space each time the variable is echoed so before long I wound up with 10 or 20 trailing spaces after the 9.

Thank you both for your replies, I really appreciate it.

Jim
9003.

Solve : To count Command line arguments (Paramaters) in .Bat file.?

Answer» HI all!!!!!!!!!

I am SENDING some parameters to a .bat file through command line. I want the count of that parameters means how many parameters I am passing. If i will enter less than the sufficient then the message should GET prompted to the user.

Can anyone please give me the solution.



thanks.You can check if a parameter is a null string

For example if you are expecting four parameters...

if "%1"=="" (
echo parameter 1 is missing
goto end
)

if "%2"=="" (
echo parameter 2 is missing
goto end
)

if "%3"=="" (
echo parameter 3 is missing
goto end
)

if "%4"=="" (
echo parameter 4 is missing
goto end
)

REM if you get here 4 parameters were passed

REM HERE IS YOUR CODE

:end
Thanks !!!!!!!!!!!!!!

It's working fine for me.

Thanks again.
9004.

Solve : QBasic 1.1?

Answer»

I cannot get the COMMANDS SOUND, PLAY or BEEP to work on WINDOWSXP Pro.
Is it possible?

Does your PC have built in motherboard loudspeaker?
TRY getting a NEWER version of qbasic, qbasic 7.1

9005.

Solve : Printing Excel files with .bat files?

Answer»

Is there a way to automatically PRINT a spread sheet from an Excel file with a batch (.bat) file?do you WANT to print to a printer? or just print the data to screen.
here's a vbscript to print to screen.
Code: [Select]Option Explicit
Dim objExcel,excelPath,worksheetCount
Dim counter,currentWorkSheet, usedRowsCount,row
Dim column,top, left, Cells, curCol,curRow,WORD
excelPath = "C:\test\Book1.xls"
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.open excelPath, FALSE, true
workSheetCount = objExcel.Worksheets.Count
For counter = 1 to workSheetCount
Set currentWorkSheet = objExcel.ActiveWorkbook.Worksheets(counter)
usedColumnsCount = currentWorkSheet.UsedRange.Columns.Count
usedRowsCount = currentWorkSheet.UsedRange.Rows.Count
top = currentWorksheet.UsedRange.Row
left = currentWorksheet.UsedRange.Column
Set Cells = currentWorksheet.Cells
For row = 0 to (usedRowsCount-1)
For column = 0 to usedColumnsCount-1
curRow = row+top
curCol = column+left
word = Cells(curRow,curCol).Value
WScript.Echo (word)
Next
Next
Set currentWorkSheet = Nothing
Next
objExcel.Workbooks(1).Close
objExcel.Quit
Set currentWorkSheet = Nothing
Set objExcel = Nothing

9006.

Solve : Start command in Batch file?

Answer»

I am trying to USE the start command for a networked printer. I cannot make the command work with a printer name that includes spaces. I TRIED using quotes but it will not FIND the printer.

Example: start \\servername\sales" "printer

Any help would be appreciated.You ENCLOSE the name which has spaces in quotes, not just the spaces!

like this!

"\\servername\sales printer"

But why are you trying to use the START command?