translate UNIX command into Windows command

Dear Radiance experts,

May I ask how to translate the following Unix command line text into Windows
command line text?

cat sensor.pts | rtrace -I -ab 1 -h -w -oov -u- scene.oct | rcalc -e
'$1=$1;$2=$2;$3=$3;$4=179*(.265*$4+.670*$5+.065*$6)' > result.dat

I've tried the following in Windows, but it doesn't seem to work:

rtrace -I -ab 1 -h -w -oov -u- scene.oct < sensor.pts > rcalc -e
'$1=$1;$2=$2;$3=$3;$4=179*(.265*$4+.670*$5+.065*$6)' > result.dat

Thanks!

Ji

Ji

···

On Tue, Jul 27, 2010 at 10:05 AM, Ji Zhang <[email protected]> wrote:

I've tried the following in Windows, but it doesn't seem to work:

rtrace -I -ab 1 -h -w -oov -u- scene.oct < sensor.pts > rcalc -e
'$1=$1;$2=$2;$3=$3;$4=179*(.265*$4+.670*$5+.065*$6)' > result.dat

The Windows command prompt doesn't understand single quotes. Use
double quotes for the "rcalc -e" expression and it should work:

rtrace -I -ab 1 -h -w -oov -u- scene.oct < sensor.pts > rcalc -e
"$1=$1;$2=$2;$3=$3;$4=179*(.265*$4+.670*$5+.065*$6)" > result.dat

Thomas

Thank you very much, Thomas!

Ji

···

On Tue, Jul 27, 2010 at 7:50 PM, Thomas Bleicher <[email protected]>wrote:

Ji

On Tue, Jul 27, 2010 at 10:05 AM, Ji Zhang <[email protected]> wrote:
> I've tried the following in Windows, but it doesn't seem to work:
>
> rtrace -I -ab 1 -h -w -oov -u- scene.oct < sensor.pts > rcalc -e
> '$1=$1;$2=$2;$3=$3;$4=179*(.265*$4+.670*$5+.065*$6)' > result.dat

The Windows command prompt doesn't understand single quotes. Use
double quotes for the "rcalc -e" expression and it should work:

rtrace -I -ab 1 -h -w -oov -u- scene.oct < sensor.pts > rcalc -e
"$1=$1;$2=$2;$3=$3;$4=179*(.265*$4+.670*$5+.065*$6)" > result.dat

Thomas

_______________________________________________
Radiance-general mailing list
[email protected]
http://www.radiance-online.org/mailman/listinfo/radiance-general

--
ZHANG Ji 张冀 (PhD) :: Research Fellow :: Centre for Sustainable Asian Cities
:: School of Design and Environment :: National University of Singapore :: 4
Architecture Drive, Singapore, 117566 :: Contact: 65-6516 5046 :: Email:
[email protected]

Dear Thomas and Radiance experts, one more question:

If I want to execute this rtrace command in windows via python, should I use
the tri-quotation symbol?

Is the following python script correct?

···

##################################################################################
import os

rtrace_command = ''rtrace -I -ab 1 -h -w -oov -u- scene.oct < sensor.pts > "
+\
                               """rcalc -e
"$1=$1;$2=$2;$3=$3;$4=179*(.265*$4+.670*$5+.065*$6)" > result.dat"""

os.system(rtrace_command)
##################################################################################

Thanks!

Ji

On Tue, Jul 27, 2010 at 7:50 PM, Thomas Bleicher <[email protected]>wrote:

Ji

On Tue, Jul 27, 2010 at 10:05 AM, Ji Zhang <[email protected]> wrote:
> I've tried the following in Windows, but it doesn't seem to work:
>
> rtrace -I -ab 1 -h -w -oov -u- scene.oct < sensor.pts > rcalc -e
> '$1=$1;$2=$2;$3=$3;$4=179*(.265*$4+.670*$5+.065*$6)' > result.dat

The Windows command prompt doesn't understand single quotes. Use
double quotes for the "rcalc -e" expression and it should work:

rtrace -I -ab 1 -h -w -oov -u- scene.oct < sensor.pts > rcalc -e
"$1=$1;$2=$2;$3=$3;$4=179*(.265*$4+.670*$5+.065*$6)" > result.dat

Thomas

_______________________________________________
Radiance-general mailing list
[email protected]
http://www.radiance-online.org/mailman/listinfo/radiance-general

Ji,

Python is quotes-agnostic, so long as you start and end with the same type,
it doesn't matter what's in between. In other words, you can use
double_quote='"' to store the " character, or single_quote="'" to store the
' character. To save the string "', you'd have to do something like
both_quotes='"'+"'". Triple quotes are for multiline strings (and comments).

Additionally, I think you'd need a pipe, which might not be Windows
friendly, or an intermediate file.

Your command would be:

#! /bin/python

import os

#with pipe
rtrace_command1 = 'rtrace -I -ab 1 -h -w -oov -u- scene.oct < sensor.pts | '
+\
                  'rcalc -e
"$1=$1;$2=$2;$3=$3;$4=179*(.265*$4+.670*$5+.065*$6)" > result.dat'

#with intermediate file
rtrace_command2a = 'rtrace -I -ab 1 -h -w -oov -u- scene.oct < sensor.pts >
tmp.file'
rtrace_command2b = 'rcalc -e
"$1=$1;$2=$2;$3=$3;$4=179*(.265*$4+.670*$5+.065*$6)" < tmp.file >
result.dat'

#should be equivalent:
os.system(rtrace_command1)

os.system(rtrace_command2a)
os.system(rtrace_command2b)

--Dave

You've got what are probably typos; the following will probably work:

rtrace_command = 'rtrace -I -ab 1 -h -w -oov -u- scene.oct < sensor.pts | \
rcalc -e "$1=$1;$2=$2;$3=$3;$4=179*(.265*$4+.670*$5+.065*$6)" \
> result.dat'

However, I recommend the Python "subprocess" module as an alternative. Subprocess avoids many of the problems of quoting by converting Python lists to command argument lists. One way of doing what you want might be:

···

# Untested code

from subprocess import Popen, communicate, PIPE

rtproc = Popen(
  "rtrace -I -ab 1 -h -w -oov -u- scene.oct".split(),
  stdin=PIPE, stdout=PIPE, universal_newlines=True)

rcproc = Popen(
  ['rcalc', '-e', '$1=$1;$2=$2;$3=$3;$4=179*(.265*$4+.670*$5+.065*$6)'],
  stdin=rtproc.stdout, stdout=PIPE)

sensor_points = open('sensor.pts', 'U')
(results,errors) = rcproc.communicate(sensor_points)
sensor_points.close()
if rtproc.returncode != 0 or rcproc.returncode != 0:
  # report errors here
# if it worked, results will be in 'results'

--
Randolph Fritz • [email protected]
Environmental Energy Technologies Division • Lawrence Berkeley Labs

On 2010-07-27 05:50:19 -0700, Ji Zhang said:

Dear Thomas and Radiance experts, one more question:

If I want to execute this rtrace command in windows via python, should I use the tri-quotation symbol?

Is the following python script correct?

##################################################################################

import

os

rtrace_command = ''rtrace -I -ab 1 -h -w -oov -u- scene.oct < sensor.pts > " +\
"""rcalc -e "$1=$1;$2=$2;$3=$3;$4=179*(.265*$4+.670*$5+.065*$6)" > result.dat"""

os.system(rtrace_command)
##################################################################################

Thanks!

Ji

On > > Tue, Jul 27, 2010 at 7:50 PM, Thomas Bleicher > <[email protected]> wrote:

Ji

On Tue, Jul 27, 2010 at 10:05 AM, Ji Zhang > <[email protected]> wrote:
> I've tried the following in Windows, but it doesn't seem to work:
>
> rtrace -I -ab 1 -h -w -oov -u- scene.oct < sensor.pts > rcalc -e
> '$1=$1;$2=$2;$3=$3;$4=179*(.265*$4+.670*$5+.065*$6)' > result.dat

The Windows command prompt doesn't understand single quotes. Use
double quotes for the "rcalc -e" expression and it should work:

rtrace -I -ab 1 -h -w -oov -u- scene.oct < sensor.pts > rcalc -e
"$1=$1;$2=$2;$3=$3;$4=179*(.265*$4+.670*$5+.065*$6)" > result.dat

Thomas

_______________________________________________
Radiance-general mailing list
[email protected]
http://www.radiance-online.org/mailman/listinfo/radiance-general
_______________________________________________
Radiance-general mailing list
[email protected]
http://www.radiance-online.org/mailman/listinfo/radiance-general

However, I recommend the Python "subprocess" module as an alternative.
Subprocess avoids many of the problems of quoting by converting Python
lists to command argument lists.

I agree that the subprocess module is the way to go.

Not to turn this into a Python discussion, but convenience functions are
very handy:

#! /bin/python

import subprocess

def execute(cmd):
    #print cmd
    p = subprocess.Popen(cmd, shell=True)
    s = os.waitpid(p.pid, 0)
    return s

def execute2(cmd):
    p = subprocess.Popen(cmd, shell=True, bufsize=1024,
stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True)
    (child_stdin, child_stdout) = (p.stdin, p.stdout)
    return (child_stdin, child_stdout)

#test Radiance calls
rpict_command = "rpict model.oct > image.hdr"
gensky_command = "gensky 4 1 12 -c"

execute(rpict_command)
f_in,f_out = execute2(gensky_command)
gensky_output = f_out.read()

--Dave

Dear David and Radiance experts,

It seems the following will work better for our original purpose of
executing rtrace and rcalc command via python in windows system:

···

##############################################################################
import os

command_rtrace = 'rtrace -I -ab 1 -h -w scene.oct < sensors.pts > temp.dat'
os.system(command_rtrace)

command_rcalc = 'rcalc -e "$1=$1;$2=$2;$3=$3;$4=.265*$4+.670*$5+.065*$6"
temp.dat > results_ir.dat'
os.system(command_rcalc)
##############################################################################

Regards,
Ji

On Tue, Jul 27, 2010 at 9:25 PM, David Smith <[email protected]> wrote:

Ji,

Python is quotes-agnostic, so long as you start and end with the same type,
it doesn't matter what's in between. In other words, you can use
double_quote='"' to store the " character, or single_quote="'" to store the
' character. To save the string "', you'd have to do something like
both_quotes='"'+"'". Triple quotes are for multiline strings (and comments).

Additionally, I think you'd need a pipe, which might not be Windows
friendly, or an intermediate file.

Your command would be:

#! /bin/python

import os

#with pipe
rtrace_command1 = 'rtrace -I -ab 1 -h -w -oov -u- scene.oct < sensor.pts |
' +\
                  'rcalc -e
"$1=$1;$2=$2;$3=$3;$4=179*(.265*$4+.670*$5+.065*$6)" > result.dat'

#with intermediate file
rtrace_command2a = 'rtrace -I -ab 1 -h -w -oov -u- scene.oct < sensor.pts >
tmp.file'
rtrace_command2b = 'rcalc -e
"$1=$1;$2=$2;$3=$3;$4=179*(.265*$4+.670*$5+.065*$6)" < tmp.file >
result.dat'

#should be equivalent:
os.system(rtrace_command1)

os.system(rtrace_command2a)
os.system(rtrace_command2b)

--Dave

_______________________________________________
Radiance-general mailing list
[email protected]
http://www.radiance-online.org/mailman/listinfo/radiance-general

--
ZHANG Ji 张冀 (PhD) :: Research Fellow :: Centre for Sustainable Asian Cities
:: School of Design and Environment :: National University of Singapore :: 4
Architecture Drive, Singapore, 117566 :: Contact: 65-6516 5046 :: Email:
[email protected]