Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Questions (Windows Mobile)
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Questions (Windows Mobile) Post any question regarding Basic4ppc.

use data from another exe (cmd)

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-07-2009, 01:32 PM
Basic4ppc Veteran
 
Join Date: Feb 2008
Location: Hilversum, The Netherlands
Posts: 295
Awards Showcase
Beta Tester 
Total Awards: 1
Default use data from another exe (cmd)

I'd like to use the data generated by cmd.exe in my desktop application,
is this possible...?

I've tried to search the forum, but i couldn't find any concrete answers


thanks
Reply With Quote
  #2 (permalink)  
Old 10-07-2009, 03:54 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,734
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

Are these two separate process which need to communicate?
Reply With Quote
  #3 (permalink)  
Old 10-07-2009, 09:27 PM
Basic4ppc Veteran
 
Join Date: Feb 2008
Location: Hilversum, The Netherlands
Posts: 295
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Well..yes
i'd like to get the output (the text that normally is written in the cmd window)
e.g. when i run shell("cmd.exe","ping 192.x.y.z")
i'd like the result in a b4p variable( or object)
This is possible with PHP, it would be very cool if B4P could also do this
Reply With Quote
  #4 (permalink)  
Old 10-08-2009, 05:33 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,734
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

You can create a small batch file with the command:
ping 192.x.x.x > 1.txt

Then run the batch file with Shell. The output will be saved to 1.txt.
Reply With Quote
  #5 (permalink)  
Old 10-08-2009, 08:40 AM
Basic4ppc Expert
 
Join Date: May 2008
Location: Berkshire, UK
Posts: 810
Awards Showcase
Beta Tester 
Total Awards: 1
Default

I have a vague recollection that you used to be able to put two commands into the shell on one line, delimited by the "pipe" character (=|), so called because it pipes the stdout of the 1st command to the stdin of the second. I think this was borrowed from Unix. Early usage: "type <file-name> | more"

Would it work with calling a Basic4PPC executable and would that transfer sufficient data in this case?

Mike.
Reply With Quote
  #6 (permalink)  
Old 10-09-2009, 03:32 PM
Basic4ppc Veteran
 
Join Date: Feb 2008
Location: Hilversum, The Netherlands
Posts: 295
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Interesting Mike,
but wouldn't that output the result to a new exe in stead of the application initiating the cmd?

Erel, this is the code for php
Code:
<?php

    $cmd = 
"C:\WINDOWS\system32\ping.exe ping 10.16.2.102 -n 1 && exit";        
    exec($cmd, $output);
    print_r($output);
?>
the code is similar to B4P, the only exception is print_r which basically shows the complete array "$output" on the page.
echo $output[5];

would also be an option...
:-)
Reply With Quote
  #7 (permalink)  
Old 10-09-2009, 05:49 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Quote:
Originally Posted by Erel View Post
You can create a small batch file with the command:
ping 192.x.x.x > 1.txt Then run the batch file with Shell. The output will be saved to 1.txt.
If you use the Process object from the Threading library you can wait until the command finishes which makes things easier. P is a Process object. Note that all the filenames are explicitly prefixed by AppPath to make sure that files are where you expect them. I had trouble if I left them out - you may or may not experience the same.
Code:
    P.New1
FileOpen(f, AppPath & 
"\doit.bat", cWrite,, cASCII)
cmd = 
"ping 127.0.0.1 > " & AppPath & "\ping.txt"
FileWrite(f,cmd )
FileClose(f)
P.Start(AppPath & 
"\doit.bat""")
P.WaitForExit(-
1)
FileOpen(f, AppPath & 
"\ping.txt", cRead)
t = FileReadToEnd(f)
FileClose(f)
Msgbox(t)
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
Reply With Quote
  #8 (permalink)  
Old 10-09-2009, 06:59 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,734
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

Two small comments:
- The file should be opened in ASCII mode as in agraham's example.
- It is better to wrap the path with quotes in case you have spaces in it:
Code:
cmd = "ping 127.0.0.1 > " & chr(34) & AppPath & "\ping.txt" & chr(34)
Reply With Quote
  #9 (permalink)  
Old 10-09-2009, 07:35 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Quote:
Originally Posted by Erel View Post
It is better to wrap the path with quotes in case you have spaces in it:
Good point Erel! I'm old-fashioned and don't put spaces in my file and folder names - somehow it just doesn't seem right to do that. I've never really got over the demise of 8.3 filenames .
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
gps data string tremara1 Questions (Windows Mobile) 2 06-02-2009 09:04 AM
data transmission WolfgangGruia Questions (Windows Mobile) 9 07-15-2008 04:56 PM
GPS Satellites map and data derez Share Your Creations 2 01-29-2008 05:04 AM
send the hex data alex_up Questions (Windows Mobile) 10 12-18-2007 04:50 AM
Best data to work with GPS Put Claude Questions (Windows Mobile) 4 10-21-2007 08:58 PM


All times are GMT. The time now is 10:30 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0